Skip to content

Instantly share code, notes, and snippets.

@himaratsu
Last active August 29, 2015 14:06
Show Gist options
  • Save himaratsu/56f6dbe66cdcc648f1b7 to your computer and use it in GitHub Desktop.
Save himaratsu/56f6dbe66cdcc648f1b7 to your computer and use it in GitHub Desktop.
アイビーインスペクタビリティ

Embeded Frameworkに入れる必要もない

  • 昔はあったっぽい

IBDesignableで編集が容易なクラスを作成

@IBDesignable
class CardView: UIView {

    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        self.initialize()
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.initialize()
    }
    
    func initialize() {
        println("initialize")
        layer.masksToBounds = false
    }

    @IBInspectable
    var borderWidth: CGFloat = 0 {
        didSet {
            layer.borderWidth = borderWidth
        }
    }
    
    @IBInspectable
    var borderColor: UIColor = UIColor.clearColor() {
        didSet {
            layer.borderColor = borderColor.CGColor
        }
    }
    
    @IBInspectable
    var cornerRadius: CGFloat = 0 {
        didSet {
            layer.cornerRadius = cornerRadius
        }
    }
    
    @IBInspectable
    var shadowOffset: CGSize = CGSizeMake(0, 0) {
        didSet {
            layer.shadowOffset = shadowOffset
        }
    }
    
    @IBInspectable
    var shadowRadius: CGFloat = 0 {
        didSet {
            layer.shadowRadius = shadowRadius
        }
    }
    
    @IBInspectable
    var shadowOpacity: Float = 0 {
        didSet {
            layer.shadowOpacity = shadowOpacity
        }
    }
    
    @IBInspectable
    var shadowColor: UIColor = UIColor.clearColor() {
        didSet {
            layer.shadowColor = shadowColor.CGColor
        }
    }
}

drawRect以外にも有効

    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        self.initialize()
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.initialize()
    }
    
    func initialize() {
        println("initialize")
        layer.masksToBounds = false
        
        var view: UIView = UIView(frame: CGRectMake(10, 10, 30, 30))
        view.backgroundColor = UIColor.orangeColor()
        self.addSubview(view)
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment