Swift 3: How to create blurred side edges/corners of a UIImageView?

前端 未结 2 1620
孤独总比滥情好
孤独总比滥情好 2020-12-31 13:47

Currently I have a CALayer applied to a UIImageView like so:

let l: CALayer = imageView.layer
l.masksToBounds = true
l.cornerRadius         


        
相关标签:
2条回答
  • 2020-12-31 14:29

    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;
    
    0 讨论(0)
  • 2020-12-31 14:39

    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
    
    0 讨论(0)
提交回复
热议问题