Swift 扩展 Storyboard 属性

论坛 期权论坛 脚本     
已经匿名di用户   2022-4-26 16:00   1757   0

可以在 Storyboard 中直接设置 UI 控件的基本样式。

import UIKit

//@IBDesignable
extension UIView {

    @IBInspectable var cornerRadius:CGFloat {
        set{
            self.layer.cornerRadius = newValue
            self.layer.masksToBounds = true
        }
        
        get{
            return self.layer.cornerRadius
        }
    }
    
    @IBInspectable var borderWidth:CGFloat {
        set{
            self.layer.borderWidth = newValue
        }
        get{
            return self.layer.borderWidth
        }
    }
    
    @IBInspectable var boderColor:UIColor {
        set{
            self.layer.borderColor = newValue.CGColor
        }
        get{
            return UIColor(CGColor: self.layer.borderColor!)
        }
    }
    
    @IBInspectable var shadowColor:UIColor{
        set{
            self.layer.shadowColor = newValue.CGColor
        }
        get{
             return UIColor(CGColor: self.layer.shadowColor!)
        }
    }
    
    @IBInspectable var shadowOffset:CGSize{
        set{
            self.layer.shadowOffset = newValue
        }
        get{
            return self.layer.shadowOffset
        }
    }
    
    @IBInspectable var shadowOpacity:Float{
        set{
            self.layer.shadowOpacity = newValue
        }
        get{
            return self.layer.shadowOpacity
        }
    }
}
复制代码

文件下载地址

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:81
帖子:4969
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP