为了方便在Storyboard面板中给View设置圆角属性, 实现和原生其他属性一样设置的方式. 现通过IBInspectable
在storyboard中给view添加扩展属性;
效果图
代码实现
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
| extension UIView {
@IBInspectable var cornerRadius: CGFloat {
get {
return layer.cornerRadius
}
set {
layer.cornerRadius = newValue
}
}
@IBInspectable var maskToBounds: Bool {
get {
return layer.masksToBounds
}
set {
layer.masksToBounds = newValue
}
}
@IBInspectable var borderColor: UIColor {
get {
return UIColor.init(cgColor: layer.borderColor!)
}
set {
layer.borderColor = newValue.cgColor
}
}
@IBInspectable var borderWidth: CGFloat {
get {
return layer.borderWidth
}
set {
layer.borderWidth = newValue
}
}
}
|