gpt4 book ai didi

ios - 使用 boundingRectWithSize :options:attributes:context: 创建动态标签

转载 作者:行者123 更新时间:2023-11-29 03:17:43 25 4
gpt4 key购买 nike

我正在尝试将我的标签大小设置为动态的,但是目前这种方法已被弃用。我知道正确的方法是:

boundingRectWithSize:options:attributes:context:

这对于修改字体大小和换行模式确实没有任何作用。

CGSize expectedLabelSize;
expectedLabelSize = [textLabel.text sizeWithFont:[UIFont fontWithName:@"Ubuntu-Bold" size:14] constrainedToSize:maximumLabelSize
lineBreakMode:NSLineBreakByWordWrapping];

是否应该使用另一种方法来更改我的标签的属性?

最佳答案

试试这个..

NSDictionary *attributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName,nil];
CGSize labelContraints = CGSizeMake(width, 105.0);//Here I set maximum height as 105 for maximum of 5 lines.
NSStringDrawingContext *context = [[NSStringDrawingContext alloc] init];
CGRect labelRect = [str boundingRectWithSize:labelContraints
options:NSStringDrawingUsesLineFragmentOrigin attributes:attributesDictionary
context:context];

注意:它将在 IOS7+

上运行

关于ios - 使用 boundingRectWithSize :options:attributes:context: 创建动态标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21477956/

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