Skip to content

Commit a455638

Browse files
committed
Fix lineBreakMode issue in NSParagraphStyle
1 parent de66e29 commit a455638

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

Sources/Views/AttributedLabel.swift

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,25 @@
3636
}
3737

3838
var attributedText: NSAttributedString? {
39-
set {
40-
label.attributedText = newValue
39+
didSet {
40+
label.attributedText = attributedText.flatMap {
41+
let res = NSMutableAttributedString(attributedString: $0)
42+
res.enumerateAttribute(.paragraphStyle, in: NSRange(location: 0, length: $0.length), options: []) { value, range, _ in
43+
if let existingParagraphStyle = value as? NSParagraphStyle {
44+
let newParagraphStyle = existingParagraphStyle.mutableCopy() as! NSMutableParagraphStyle
45+
newParagraphStyle.lineBreakMode = lineBreakMode
46+
res.addAttribute(.paragraphStyle, value: newParagraphStyle, range: range)
47+
}
48+
}
49+
return res
50+
}
4151

42-
if let attributedString = newValue {
52+
if let attributedString = attributedText {
4353
textEngine?.textStorage.setAttributedString(attributedString)
4454
} else {
4555
textEngine?.textStorage.setAttributedString(NSAttributedString())
4656
}
4757
}
48-
get {
49-
return label.attributedText
50-
}
5158
}
5259

5360
var numberOfLines: Int {

Sources/Views/BaseAttributedTextView.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,6 @@
517517

518518
let paragraphStyle = NSMutableParagraphStyle()
519519
paragraphStyle.alignment = textAlignment
520-
paragraphStyle.lineBreakMode = lineBreakMode
521520
paragraphStyle.lineBreakStrategy = lineBreakStrategy
522521

523522
var inheritedAttributes: [NSAttributedString.Key: Any] = [

0 commit comments

Comments
 (0)