Xcode6.1 自定义控件写到库里面。在storyboard里使用。
1.add target -- FrameWork&Library--cocoaTouch framework
2.添加一个文件myView,继承自UIView
3.在myView中初始化以便跟storyboard关联
4.storyboard中拖入一个50,50,200,200的view,绑定myView类
5.在myView类中定制view的属性。
@IBDesignable class MyView: UIView {
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init(frame: CGRect) {
super.init(frame: frame)
}
@IBInspectable var name:String = "view"
@IBInspectable var borderWith:CGFloat=0{
didSet{
layer.borderWidth = borderWith
}
}
@IBInspectable var borderColor:UIColor=UIColor.clearColor(){
didSet{
layer.borderColor = borderColor.CGColor
}
}
@IBInspectable var cornerRadius:CGFloat=0{
didSet{
layer.cornerRadius = cornerRadius
}
}