Add the padding to the label iOS swift
Solution:
You can use the below method to add padding in the label in left side.
class PaddingLabel: UILabel {
let padding = UIEdgeInsets(top: 0, left: 8, bottom: 0, right: 0)
override func drawText(in rect: CGRect) {
super.drawText(in: rect.inset(by: padding))
}
override var intrinsicContentSize : CGSize {
let superContentSize = super.intrinsicContentSize
let width = superContentSize.width + padding.left + padding.right
let height = superContentSize.height + padding.top + padding.bottom
return CGSize(width: width, height: height)
}
}
Add the above code in any class then in storyboard go and set the class to the label as PaddingLabel then it will works automatically
Comments
Post a Comment