Created
July 18, 2018 15:46
-
-
Save hintoz/33733200b7d00b82d44df755784ccb91 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BorderedLabel: UILabel { | |
@IBInspectable var topInset: CGFloat = 0.0 | |
@IBInspectable var bottomInset: CGFloat = 0.0 | |
@IBInspectable var leftInset: CGFloat = 5.0 | |
@IBInspectable var rightInset: CGFloat = 5.0 | |
@IBInspectable var color: UIColor = .white | |
override func drawText(in rect: CGRect) { | |
let insets = UIEdgeInsets.init(top: topInset, left: leftInset, bottom: bottomInset, right: rightInset) | |
super.drawText(in: UIEdgeInsetsInsetRect(rect, insets)) | |
} | |
override var intrinsicContentSize: CGSize { | |
get { | |
var contentSize = super.intrinsicContentSize | |
contentSize.height += topInset + bottomInset | |
contentSize.width += leftInset + rightInset | |
return contentSize | |
} | |
} | |
override func awakeFromNib() { | |
layer.borderWidth = 1.0 | |
layer.cornerRadius = 8 | |
layer.borderColor = color.cgColor | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment