ALabel 有边框
class ALabel: UILabel {
@IBInspectable var insets: UIEdgeInsets = .zero {
didSet {
invalidateIntrinsicContentSize()
setNeedsLayout()
}
}
// MARK: Initialization
override init(frame: CGRect) {
super.init(frame: frame)
setupView()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setupView()
}
// MARK: Padding
override func drawText(in rect: CGRect) {
super.drawText(in: rect.inset(by: insets))
}
override var intrinsicContentSize: CGSize {
var size = super.intrinsicContentSize
size.width += insets.left + insets.right
size.height += insets.top + insets.bottom
return size
}
@IBInspectable var cornerRadius: CGFloat {
get {
return layer.cornerRadius
}
set {
layer.cornerRadius = newValue
}
}
}
本文标题:ALabel 有边框
本文链接:https://www.haomeiwen.com/subject/vgsdsltx.html
网友评论