77
88import UIKit
99
10- public class PaddingLabel : UILabel {
10+ public final class PaddingLabel : UILabel {
1111 private struct AssociatedKeys {
1212 static var padding = UIEdgeInsets ( )
1313 }
@@ -23,15 +23,15 @@ public class PaddingLabel: UILabel {
2323 }
2424 }
2525
26- override open func draw( _ rect: CGRect ) {
26+ public override func draw( _ rect: CGRect ) {
2727 if let insets = padding {
2828 self . drawText ( in: rect. inset ( by: insets) )
2929 } else {
3030 self . drawText ( in: rect)
3131 }
3232 }
3333
34- override open var intrinsicContentSize : CGSize {
34+ public override var intrinsicContentSize : CGSize {
3535 guard let text = self . text else { return super. intrinsicContentSize }
3636
3737 var contentSize = super. intrinsicContentSize
@@ -45,9 +45,11 @@ public class PaddingLabel: UILabel {
4545 textWidth -= insetsWidth
4646 }
4747
48+ let customFont : UIFont = font ?? . systemFont( ofSize: 16 , weight: . regular)
4849 let newSize = text. boundingRect ( with: CGSize ( width: textWidth, height: CGFloat . greatestFiniteMagnitude) ,
4950 options: NSStringDrawingOptions . usesLineFragmentOrigin,
50- attributes: [ NSAttributedString . Key. font: self . font ?? UIFont . systemFont ( ofSize: 16 , weight: . regular) ] , context: nil )
51+ attributes: [ . font: customFont] ,
52+ context: nil )
5153
5254 contentSize. height = ceil ( newSize. size. height) + insetsHeight
5355 contentSize. width = ceil ( newSize. size. width) + insetsWidth
0 commit comments