UIView图层常用属性:
- 边角半径
- 阴影色及偏移
- 阴影透明度
- 边框粗细和颜色
扩展UIView
import UIKit
extension UIView {
//圆角半径
@IBInspectable
var cornerRadius: CGFloat {
get {
return layer.cornerRadius
}
set {
layer.cornerRadius = newValue
}
}
//阴影圆角半径
@IBInspectable
var shadowRadius: CGFloat {
get {
return layer.shadowRadius
}
set {
layer.shadowRadius = newValue
}
}
//阴影透明度
@IBInspectable
var shadowOpacity: Float {
get {
return layer.shadowOpacity
}
set {
layer.shadowOpacity = newValue
}
}
//阴影颜色
@IBInspectable
var shadowColor: UIColor? {
get {
return layer.shadowColor != nil ? UIColor.init(cgColor: layer.shadowColor!) : nil
}
set {
layer.shadowColor = newValue?.cgColor
}
}
//阴影偏移
@IBInspectable
var shadowOffset: CGSize {
get {
return layer.shadowOffset
}
set {
layer.shadowOffset = newValue
}
}
}
这样就可以直接在storyboard和xib中设置UIView的图层属性
网友评论