1. 程式人生 > >Swift 擴充套件 Storyboard 屬性

Swift 擴充套件 Storyboard 屬性

可以在 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 } } }