UIButton bottom shadow

后端 未结 11 1162
-上瘾入骨i
-上瘾入骨i 2020-12-12 14:14

I have a UIButton which is very similar to the standard iOS keyboard alphabet button.

I am not sure how to create a shadow only for the bottom layer li

11条回答
  •  鱼传尺愫
    2020-12-12 14:43

    SWIFT 3

    import UIKit
    
    class ButtonWithShadow: UIButton {
    
        override func draw(_ rect: CGRect) {
            updateLayerProperties()
        }
    
        func updateLayerProperties() {
            self.layer.shadowColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.25).cgColor
            self.layer.shadowOffset = CGSize(width: 0, height: 3)
            self.layer.shadowOpacity = 1.0
            self.layer.shadowRadius = 10.0
            self.layer.masksToBounds = false
        }
    
    }
    

    !! Only if you do not need corner radius and shadow simultaneously. Otherwise watch this.

提交回复
热议问题