UILabel에 Padding 추가하기

김정윤·2023년 3월 10일
class PaddingLabel: UILabel {

	var padding = UIEdgeInsets(top: 6, left: 8, bottom: 6, right: 8)
    
	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)
    }
}
profile
iOS앱개발자

0개의 댓글