使用IBInspectable在面板上添加属性

//
//  UIView+SKAddition.swift
//  kkShop
//
//  Copyright (c) 2015年 kk. All rights reserved.
//

@IBDesignable
extension UIView {
    
    @IBInspectable var cornerRadius: CGFloat {
        get {
            return layer.cornerRadius
        }
        set {
            layer.cornerRadius = newValue
            layer.masksToBounds = newValue > 0
        }
    }
 
    @IBInspectable var borderWidth: CGFloat {
        get {
            return layer.borderWidth
        }
        set {
            layer.borderWidth = newValue
        }
    }

    @IBInspectable var borderColor: UIColor? {
        get {
            if (layer.borderColor != nil) {
                return UIColor(CGColor: layer.borderColor!)
            }
            
            return self.backgroundColor
        }
        set {
            layer.borderColor = newValue?.CGColor
        }
    }
}

你可能感兴趣的:(使用IBInspectable在面板上添加属性)