Outer glow for UIView
I am wondering how I can create an external glow effect outside of a UIView on an iPhone, sort of like when clicking a regular NSTextField on a Mac.
Thanks for any help!
+2
PF1
source
to share
3 answers
You can add a custom subview to your UIView that extends outside of your UIView. For example:
UITextView* mainView = [[UITextView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
mainView.clipsToBounds = NO;
// Add 5 px of padding to the mainView bounds
CGRect borderFrame = CGRectInset(mainView.bounds, -5, -5);
MyBorderView* borderView = [[MyBorderView alloc] initWithFrame:borderFrame];
customView.userInteractionEnabled = NO;
[mainView addSubview:customView];
MyBorderView
can draw border in your method -drawRect:
, or you can use UIImageView.
+4
Darren
source
to share
You can create a background image, place it behind the TextField and enlarge it slightly so that some of the glow appears around the borders of the text field.
+1
Andrew Johnson
source
to share
If your view is opaque, just add a drop shadow to its layer:
view.layer.shadowOpacity = 0.5
view.layer.shadowOffset = CGSizeZero
view.layer.shadowRadius = 5.0
view.layer.shadowColor = self.window!.tintColor.CGColor
+1
jrc
source
to share