gpt4 book ai didi

iphone - 大小和字体 :forwidth:linebreakmode

转载 作者:塔克拉玛干 更新时间:2023-11-01 19:11:26 26 4
gpt4 key购买 nike

为什么这行不通?无论字符串的长度如何,它总是返回 18。有 this thread ,但不是确定的答案。

    NSString * t = @"<insert super super long string here>";

CGSize size = [t sizeWithFont:[UIFont systemFontOfSize:14.0] forWidth:285 lineBreakMode:UILineBreakModeWordWrap];

NSLog(@"size.height is %f and text is %@", size.height, t);

谢谢,

托德

最佳答案

改用 sizeWithFont:constrainedToSize:lineBreakMode:

NSString * t = @"<insert super super long string here>";
CGSize constrainSize = CGSizeMake(285, MAXFLOAT);
CGSize size = [t sizeWithFont:[UIFont systemFontOfSize:14.0] constrainedToSize:constrainSize lineBreakMode:UILineBreakModeWordWrap];
NSLog(@"size.height is %f and text is %@", size.height, t);

关于iphone - 大小和字体 :forwidth:linebreakmode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12273804/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com