……

IOS自定义样式


extension UIView{
    //圆角
    @IBInspectable public
    var cornerRadius: CGFloat {
        get {
            return layer.cornerRadius
        }
        set {
            layer.cornerRadius = newValue
        }
    }
    //阴影圆角
    @IBInspectable public
    var shadowRadius: CGFloat {
        get {
            return layer.shadowRadius
        }
        set {
            layer.shadowRadius = newValue
        }
    }
    //透明度
    @IBInspectable public
    var shadowOpacity: Float {
        get {
            return layer.shadowOpacity
        }
        set {
            layer.shadowOpacity = newValue
        }
    }
    //阴影颜色
    @IBInspectable public
    var shadowColor: UIColor? {
        get {
            return layer.shadowColor != nil ? UIColor(cgColor: layer.shadowColor!) : nil
        }
        set {
            layer.shadowColor = newValue?.cgColor
        }
    }
    //阴影偏移
    @IBInspectable public
    var shadowOffset:CGSize{
        get{
            return layer.shadowOffset
        }
        set{
            layer.shadowOffset = newValue
        }
    }
}```
保存为UIViewHelper.swift

posted on 2020-10-27 13:58  Exlo  阅读(66)  评论(0编辑  收藏  举报

导航