Question

I am wondering how I can create an outer glow effect outside a UIView on the iPhone, kind of like when clicking a regular NSTextField on the Mac.

Thanks for any help!

Was it helpful?

Solution

You can add a custom subview to your UIView that extends beyond the bounds 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 a border in its -drawRect: method, or you could use UIImageView.

OTHER TIPS

You could create a background image, position it behind the TextField, and have it be slightly larger so the glow part of the image shows around the borders of the text field.

If your view is opaque, just add a 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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top