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

标签 ios objective-c xcode7

谁能帮我解决这个警告?

'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/

相关文章:

ios - 如何更改 Crashlytics Beta 电子邮件邀请中的应用程序名称

ios - 创建要在 iPhone 配置实用程序中使用的构建文件(.app 和 .mobileprovision)

javascript - html 下拉选择选项在 iPhone 上看起来很丑

JavaScriptCore - 在 iOS 中访问 DOMParser

ios - iOS中如何获取调用方法的对象?

ios - Xcode UI 测试手册截图

ios - XCode iPhone 模拟器看起来不像 iPhone

iphone - iOS 中的内存泄漏

objective-c - 完全重置 OS X Mountain Lion 的 Twitter/Facebook 应用程序权限

profiling - Xcode7 能量分析仪的 "Overhead"是什么?