Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
271 views
in Technique[技术] by (71.8m points)

ios - Why does calculate text bounds is different between UILabel and CoreText?

It has the same height between iOS13 Or iOS 14 with the same words in the label . But It's different from when I use the CoreText .For example:

click the UIlabel and obtain the last line bounds with CoreText is different

    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc]initWithString:@"107年前(743年),世界上突然出现了人类的天敌“巨人”。面临着生存危机而残存下来的。107年前(743年),世界上突然出现了人类的天敌“巨人”。面临着生存危机而残存下来的。107年前(743年),世界上突然出现了人类的天敌“巨人”。面临着生存危机而残存下来的。107年前(743年),世界上突然出现了人类的天敌“巨人”。面临着生存危机而残存下来的。];
    [attri addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16]} range:NSMakeRange(0, attri.length)];
        NSMutableParagraphStyle *paraStyle = [NSMutableParagraphStyle new];
        paraStyle.lineSpacing = 4;
        
        [attri addAttribute:NSParagraphStyleAttributeName value:paraStyle range:NSMakeRange(0, attri.length)];

In iOS 13 or iOS 14 The UIlabel Bounds is CGRect(0 0; 232 250.5)

But the result of Coretext obtain the LastLine Height In iOS13 is (CGRect) lineBounds = (origin = (x = 0, y = 212.24000000000001), size = (width = 114.23999999999998, height = 16));

the result of Coretext LastLine Height In iOS14 is (CGRect) lineBounds = (origin = (x = 0, y = 231.24000000000001), size = (width = 114.23999999999998, height = 16));

why it's different betweeen iOS 13 and iOS14 about the point.y

question from:https://stackoverflow.com/questions/66057278/why-does-calculate-text-bounds-is-different-between-uilabel-and-coretext

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...