Padin215
Padin215

Reputation: 7484

UIView with blurred border

Is there a way to blur/fade out the border of a UIView?

i have done very little to none with core graphics so far.

Upvotes: 6

Views: 7558

Answers (2)

LightMan
LightMan

Reputation: 3575

Adding an example with the swift version:

    btnSignIn.layer.cornerRadius = btnSignIn.frame.height * 0.5
    btnSignIn.layer.shadowColor = UIColor.darkGray.cgColor
    btnSignIn.layer.shadowRadius = 4.0
    btnSignIn.layer.shadowOpacity = 1.0
    btnSignIn.layer.shadowOffset = CGSize(width: 0, height: 0)

Result:

enter image description here

Keep in mind that if you change the shadow settings in the ib editor, it will change the text's shadow, not the view's border.

Also you can make a class and set it in IB Builder:

class UIRoundedWhiteButton: UIButton {

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)

    layer.cornerRadius = frame.height * 0.5
    layer.shadowColor = UIColor.darkGray.cgColor
    layer.shadowRadius = 4.0
    layer.shadowOpacity = 1.0
    layer.shadowOffset = CGSize(width: 0, height: 0)
}...

Upvotes: 2

Mike M
Mike M

Reputation: 4436

You might try setting the UIView's CALayer with a large shadow radius and transparency. Something like:

    #include <QuartzCore/QuartzCore.h>

...

    CALayer *layer = myView.layer;
    layer.shadowOpacity = .5;
    layer.shadowColor = [[UIColor blackColor] CGColor];
    layer.shadowOffset = CGSizeMake(0,0);
    layer.shadowRadius = 10;

Upvotes: 15

Related Questions