What is the best way to create a shadow behind a UIImageView

前端 未结 4 2011
再見小時候
再見小時候 2020-11-30 18:21

I have a UIImageView that I want to add a shadow behind. I wish that apple had that as a property but they have to make lots of things hard for us programmers so I need to a

4条回答
  •  日久生厌
    2020-11-30 18:46

    Swift solution with extension. Subclassing is not required. Call myImage.addShadow() from viewDidLoad(). This should work for UIView and UIImageView.

    extension UIView {
    
        func addShadow() {
            layer.shadowColor = UIColor.black.cgColor
            layer.shadowOffset = CGSize(width: 0, height: 0)
            layer.shadowOpacity = 0.5
            layer.shadowRadius = 5
            clipsToBounds = false
        }
    }
    

提交回复
热议问题