Use Storyboard to mask UIView and give rounded corners?

前端 未结 4 2042
余生分开走
余生分开走 2020-12-23 00:23

Lots of questions like this explain how to programmatically create a mask and provide rounded corners to a UIView.

Is there a way to do it all within Storyboard? Jus

4条回答
  •  渐次进展
    2020-12-23 00:57

    Select view

    extension UIView {
    
        @IBInspectable var cornerRadiusV: CGFloat {
            get {
                return layer.cornerRadius
            }
            set {
                layer.cornerRadius = newValue
                layer.masksToBounds = newValue > 0
            }
        }
    
        @IBInspectable var borderWidthV: CGFloat {
            get {
                return layer.borderWidth
            }
            set {
                layer.borderWidth = newValue
            }
        }
    
        @IBInspectable var borderColorV: UIColor? {
            get {
                return UIColor(cgColor: layer.borderColor!)
            }
            set {
                layer.borderColor = newValue?.cgColor
            }
        }
    }
    

提交回复
热议问题