思路:扩展UIView,添加属性ayCornerRadius,用IBInspectable来修饰后在IB的Attributes inspector中就会显示,具体怎么做,很简单:
1、新建文件Extension-UIView.swift (文件名随便取不重要,下面的代码才重要)
2、编辑以下代码
extension UIView {
@IBInspectable var ayCornerRadius: CGFloat {
get {
return layer.cornerRadius
}
// also set(newValue)
set {
layer.masksToBounds = true
layer.cornerRadius = newValue
}
}
}
3、查看interface buider: