gpt4 book ai didi

ios - 'sizeWithFont :constrainedToSize:lineBreakMode:' is deprecated: first deprecated in iOS 7. 0 - 使用 -boundingRectWithSize:options:attributes:context:

转载 作者:行者123 更新时间:2023-11-28 19:45:02 24 4
gpt4 key购买 nike

谁能帮我解决这个警告?

'sizeWithFont:constrainedToSize:lineBreakMode:' 已弃用:首先在 iOS 7.0 中弃用 - 使用 -boundingRectWithSize:options:attributes:context:

-(CGFloat)setLableSizeAccordingToText:(NSString*)text andSetX:(CGFloat)x Y:(CGFloat)y{

self.text = text;


CGSize maximumLabelSize = CGSizeMake(296, FLT_MAX);

CGSize expectedLabelSize = [text sizeWithFont:self.font constrainedToSize:maximumLabelSize lineBreakMode:self.lineBreakMode];

CGRect frame = CGRectMake(x, y, expectedLabelSize.width+lblHorizontalPadding , lblHeight);

self.frame = frame;

return expectedLabelSize.width + lblHorizontalPadding;
}

最佳答案

对我有用

UILabel *myLabel;
CGSize textSize;
if (!SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")){
textSize = [myLabel.text sizeWithFont:[myLabel font]];
}else{
textSize = [myLabel.text sizeWithAttributes:[NSDictionary dictionaryWithObject:[myLabel font] forKey:NSFontAttributeName]];
}

关于ios - 'sizeWithFont :constrainedToSize:lineBreakMode:' is deprecated: first deprecated in iOS 7. 0 - 使用 -boundingRectWithSize:options:attributes:context:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32645760/

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