Currently I have a CALayer
applied to a UIImageView
like so:
let l: CALayer = imageView.layer
l.masksToBounds = true
l.cornerRadius = 20.0
I'd like to achieve the following blurred effect as shown:
I've tried the following:
let blurEffect = UIBlurEffect(style: .light)
let visualEffectView = UIVisualEffectView(effect: blurEffect)
imageView.addSubview(visualEffectView)
as well as:
var visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .light))
visualEffectView.frame = staffImageView.bounds
imageView.addSubview(visualEffectView)
However, both do not achieve the results I want.
Can someone provide help on this? This seems rather simple, but I just cannot achieve it.
UPDATE: I've tried to play around with the gradient but not having much luck:
var maskLayer = CAGradientLayer()
maskLayer.frame = cell.imageView.bounds
let black = UIColor.white.cgColor
let clear = UIColor(white: 1, alpha: 0).cgColor
maskLayer.colors = [black, clear]
maskLayer.locations = [0.0, 0.10]
maskLayer.startPoint = CGPoint(x: 1, y: 0)
maskLayer.endPoint = CGPoint(x: 1, y: 1)
cell.imageView.layer.addSublayer(maskLayer)
Result:
Base on Vincent Joy post,
Swift 3:
Swift 4:
Swift 4