Skip to content

Commit 55af654

Browse files
committed
fix CSPaddingLabel bug
1 parent b99ed33 commit 55af654

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

LTXiOSUtilsDemo/Podfile.lock

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,19 @@ DEPENDENCIES:
3838
- SwiftFormat/CLI (= 0.47.13)
3939

4040
SPEC REPOS:
41-
https://github.com/CocoaPods/Specs.git:
42-
- SnapKit
4341
trunk:
42+
- SnapKit
4443
- SwiftFormat
4544

4645
EXTERNAL SOURCES:
4746
LTXiOSUtils:
4847
:path: "../"
4948

5049
SPEC CHECKSUMS:
51-
LTXiOSUtils: 415221c5e6ae52499ffdda92a1d15a7aec530147
50+
LTXiOSUtils: b2f2a0ab25a055b8327016c7f3f60e65e2e1c218
5251
SnapKit: e01d52ebb8ddbc333eefe2132acf85c8227d9c25
5352
SwiftFormat: 73573b89257437c550b03d934889725fbf8f75e5
5453

5554
PODFILE CHECKSUM: 22b4fa9a0141ec7bf2eb5b85fa34371b43861711
5655

57-
COCOAPODS: 1.11.3
56+
COCOAPODS: 1.16.2

Sources/LTXiOSUtils/Classes/Component/Class/CSPaddingLabel.swift

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,28 @@ open class CSPaddingLabel: UILabel {
4040
}
4141
}
4242

43-
open override func drawText(in rect: CGRect) {
44-
let insets = UIEdgeInsets(top: topInset, left: leftInset, bottom: bottomInset, right: rightInset)
45-
super.drawText(in: rect.inset(by: insets))
43+
override open func textRect(forBounds bounds: CGRect, limitedToNumberOfLines numberOfLines: Int) -> CGRect {
44+
let insetRect = bounds.inset(by: edgeInsets)
45+
let textRect = super.textRect(forBounds: insetRect, limitedToNumberOfLines: numberOfLines)
46+
let invertedInsets = UIEdgeInsets(
47+
top: -edgeInsets.top,
48+
left: -edgeInsets.left,
49+
bottom: -edgeInsets.bottom,
50+
right: -edgeInsets.right
51+
)
52+
return textRect.inset(by: invertedInsets)
4653
}
4754

48-
open override var intrinsicContentSize: CGSize {
55+
override open func drawText(in rect: CGRect) {
56+
super.drawText(in: rect.inset(by: edgeInsets))
57+
}
58+
59+
override open var intrinsicContentSize: CGSize {
4960
let size = super.intrinsicContentSize
5061
return CGSize(width: size.width + leftInset + rightInset, height: size.height + topInset + bottomInset)
5162
}
5263

53-
open override func sizeThatFits(_ size: CGSize) -> CGSize {
64+
override open func sizeThatFits(_ size: CGSize) -> CGSize {
5465
let size = super.sizeThatFits(size)
5566
return CGSize(width: size.width + leftInset + rightInset, height: size.height + topInset + bottomInset)
5667
}

0 commit comments

Comments
 (0)