Currently I have a CALayer
applied to a UIImageView
like so:
let l: CALayer = imageView.layer
l.masksToBounds = true
l.cornerRadius
Base on Vincent Joy post,
Swift 3:
let maskLayer = CAGradientLayer()
maskLayer.frame = yourImageView.bounds
maskLayer.shadowRadius = 5
maskLayer.shadowPath = CGPathCreateWithRoundedRect(CGRectInset(yourImageView.bounds, 5, 5), 10, 10, nil)
maskLayer.shadowOpacity = 1;
maskLayer.shadowOffset = CGSizeZero;
maskLayer.shadowColor = UIColor.whiteColor().CGColor
yourImageView.layer.mask = maskLayer;
Swift 4:
let maskLayer = CAGradientLayer()
maskLayer.frame = YourImagView.bounds
maskLayer.shadowRadius = 5
maskLayer.shadowPath = CGPath(roundedRect: YourImagView.bounds.insetBy(dx: 5, dy: 5), cornerWidth: 10, cornerHeight: 10, transform: nil)
maskLayer.shadowOpacity = 1;
maskLayer.shadowOffset = CGSize.zero;
maskLayer.shadowColor = UIColor.white.cgColor
YourImagView.layer.mask = maskLayer;
Swift 4
let maskLayer = CAGradientLayer()
maskLayer.frame = yourImageView.bounds
maskLayer.shadowRadius = 5
maskLayer.shadowPath = CGPath(roundedRect: YourImagView.bounds.insetBy(dx: 5, dy: 5), cornerWidth: 10, cornerHeight: 10, transform: nil)
maskLayer.shadowOpacity = 1
maskLayer.shadowOffset = CGSize.zero
maskLayer.shadowColor = UIColor.white.cgColor
yourImageView.layer.mask = maskLayer