谁能帮我解决这个警告?
'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/