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.
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;
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:
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)
}...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With