Before iOS 17, CTFrameGetLines(ctFrame)
returns exact number of lines it will displayed on the screen. However after iOS 17.2.x, under some unknown condition, it returns less CTLines. It's easy to reproduce:
let formattedString = NSMutableAttributedString()
formattedString.append(.init(string: "你", attributes: [.font: UIFont.boldSystemFont(ofSize: 14)]))
formattedString.append(.init(string: "\n\n\n\n\n\n好\n"))
let ctSetter = CTFramesetterCreateWithAttributedString(formattedString as CFAttributedString)
let rect = CGRect(x: 0, y: 0, width: 100, height: 1000)
let bezierPath = UIBezierPath(rect: rect)
let ctFrame = CTFramesetterCreateFrame(ctSetter, CFRangeMake(0, formattedString.length), bezierPath.cgPath, nil)
let ctLines = CTFrameGetLines(ctFrame)
print("CTLine count: \(CFArrayGetCount(ctLines))")
The test code above should print CTLine count: 7
, but actually it returns 4
. One weird CTLine is like:
- 1 : <CTLine: 0x3031e0780>{run count = 1, string range = (2, 3), width = 0, A/D/L = 9.24023/2.75977/0, glyph count = 3, runs = (
<CTRun: 0x10173ec50>{string range = (2, 3), string = "\n\n\n", attributes = {
NSFont = "<UICTFont: 0x101728800> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 12.00pt";
}}
)
}
never met this issue before, is it a bug or just new feature...