I have a UIImage with a UIVisualEffectView on top of it. I want to make the edges softer to give it a shadow effect.
I tried playing around with maskToBounds
but it doesn't make a difference.
let weekndImage = UIImage(named: "weeknd.jpg")
let weekndIV = UIImageView(image: weekndImage)
weekndIV.frame.size = CGSize(width: 200, height: 200)
let blur = UIBlurEffect(style: .light)
let blurView = UIVisualEffectView(effect: blur)
blurView.frame = weekndIV.bounds
weekndIV.addSubview(blurView)
weekndIV.layer.cornerRadius = 10
weekndIV.layer.masksToBounds = true
move these two lines after setting the blurView frame and before adding blurView to weekndIV view
weekndIV.layer.cornerRadius = 10
weekndIV.layer.masksToBounds = true
I think you want to have a shadow effect on your view. For that you can access shadowOpacity
and shadowRadius
from layer
of your view
For example in Swift 2 :
class MyView : UIView {
override func awakeFromNib() {
layer.cornerRadius = 5.0
layer.shadowOpacity = 0.8
layer.shadowRadius = 5.0
layer.shadowOffset = CGSizeMake(2.0, 2.0)
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.