Post

Replies

Boosts

Views

Activity

Reply to What is difference between lineFragmentRect and lineFragmentUsedRect in TextKit?
After few hours later, I cloud solve this question by myself. These are difference that my screenshots claim: ・lineFragmentRect ・lineFragmentUsedRect Please look at the right edge of red borders. These maxX and width are not equal. Assuming from this behavior, I understand that lineFragmentRect is rect for proposing line fragment in glyph layout process, and lineFragmentUsedRect is actual rect that the glyphs are filled, considering word wrap and hyphen factor. ・Code I used for investigation.     func addLineFragmentBorder(of text: String) {         let range = (textView.text as NSString).range(of: text)         let glyphRange = textView.layoutManager.glyphRange(forCharacterRange: range, actualCharacterRange: nil) // You can try the difference by changing `lineFragmentUsedRect` to `lineFragmentRect`.         let lineRect = textView.layoutManager.lineFragmentUsedRect(forGlyphAt: glyphRange.location, effectiveRange: nil)         let borderLayer = CALayer()         borderLayer.frame = .init(x: lineRect.minX, y: lineRect.minY + textView.textContainerInset.top, width: lineRect.width, height: lineRect.height)         borderLayer.borderColor = UIColor.red.cgColor         borderLayer.borderWidth = 2         borderLayer.backgroundColor = UIColor.clear.cgColor         textView.layer.addSublayer(borderLayer)     }
Topic: App & System Services SubTopic: General Tags:
Oct ’21