UIView with rounded corners and drop shadow?

前端 未结 30 3010
一整个雨季
一整个雨季 2020-11-22 08:00

I’ve been working on an application for a couple of years and received a simple design request: Round the corners on a UIView and add a drop shadow.To do as given below.

30条回答
  •  故里飘歌
    2020-11-22 08:21

    Swift 4 : Create Subclass of UIView

    class ShadowView: UIView {
    
        required init?(coder aDecoder: NSCoder) {
            super.init(coder: aDecoder)
    
            // corner radius
            self.layer.cornerRadius = 10
    
            // border
            self.layer.borderWidth = 1.0
            self.layer.borderColor = UIColor.black.cgColor
    
            // shadow
            self.layer.shadowColor = UIColor.black.cgColor
            self.layer.shadowOffset = CGSize(width: 3, height: 3)
            self.layer.shadowOpacity = 0.7
            self.layer.shadowRadius = 4.0
        }
    
    }
    

    Using..

提交回复
热议问题