Skip to content

Commit 8a9eee7

Browse files
committed
发布1.4.1, 修复UILabel 点击范围计算错误的问题
1 parent 8c582ad commit 8a9eee7

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

AttributedString.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = "AttributedString"
4-
s.version = "1.4.0"
4+
s.version = "1.4.1"
55
s.summary = "基于Swift字符串插值快速构建你想要的富文本"
66

77
s.homepage = "https://github.com/lixiang1994/AttributedString"

Sources/Extension/UIKit/UILabelExtension.swift

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ extension AttributedStringWrapper where Base: UILabel {
3232
base.attributedText = AttributedString(
3333
newValue?.value,
3434
.font(base.font),
35-
.paragraph(.alignment(base.textAlignment), .lineBreakMode(base.lineBreakMode))
35+
.paragraph(.alignment(base.textAlignment))
3636
)?.value
3737

3838
#if os(iOS)
@@ -156,6 +156,11 @@ fileprivate extension UILabel {
156156
textContainer.lineFragmentPadding = 0.0
157157
textContainer.maximumNumberOfLines = numberOfLines
158158

159+
// subviews.forEach({ $0.removeFromSuperview() })
160+
// let view = DebugView(frame: bounds)
161+
// view.draw = { layoutManager.drawGlyphs(forGlyphRange: .init(location: 0, length: textStorage.length), at: .zero) }
162+
// addSubview(view)
163+
159164
// 获取文本所占高度
160165
let height = layoutManager.usedRect(for: textContainer).height
161166

@@ -181,6 +186,25 @@ fileprivate extension UILabel {
181186
}
182187
}
183188

189+
fileprivate class DebugView: UIView {
190+
var draw: (() -> Void)?
191+
192+
override init(frame: CGRect) {
193+
super.init(frame: frame)
194+
isUserInteractionEnabled = false
195+
backgroundColor = .clear
196+
}
197+
198+
required init?(coder: NSCoder) {
199+
fatalError("init(coder:) has not been implemented")
200+
}
201+
202+
override func draw(_ rect: CGRect) {
203+
super.draw(rect)
204+
self.draw?()
205+
}
206+
}
207+
184208
#endif
185209

186210
#endif

0 commit comments

Comments
 (0)