I'm trying to use replaceCharacters(in:with:) of NSMutableAttributedString to replace a substring and apply different attributes. The problem is strikethroughStyle is not rendered for that substring.
let s = NSMutableAttributedString(
string: "hello world!",
attributes: [.foregroundColor: UIColor.label]
)
let range = s.mutableString.range(of: "world")
s.replaceCharacters(
in: range,
with: NSAttributedString(
string: "mars",
attributes: [
.strikethroughStyle: NSUnderlineStyle.single.rawValue,
.strikethroughColor: UIColor.systemRed,
.foregroundColor: UIColor.systemRed,
]
)
)
Here, I can see that the color of the substring "mars" is changed, but there is no strikethrough line.
The same code is successfully working for iOS 13.
Post
Replies
Boosts
Views
Activity
I've a custom UIView to render a large piece of text using CATiledLayers. My draw(rect:) implementation is quite simple:
override func draw(_ rect: CGRect) {
	let range = layoutManager.glyphRange(forBoundingRect: rect, in: textContainer)
	layoutManager.drawBackground(forGlyphRange: range, at: .zero)
	layoutManager.drawGlyphs(forGlyphRange: range, at: .zero)
}
This code works without any issue on iOS 13, but fails with a crash on iOS 14 simulator:
Thread 9: EXC_BAD_ACCESS (code=1, address=0x28)
#0 0x00007fff2396a3f5 in _NSLayoutTreeMoveToGlyphIndex ()
I can see that draw(rect:) is being called from different threads in both iOS 13 and 14. However the EXC_BAD_ACCESS has never happened so far in iOS 13.
I wonder whether this is a behaviour change in iOS 14 or an issue. If this is a change in NSLayoutManager, then is it still possible to use CATiledLayer to render large amount of text in coordination with NSLayoutManager?