83

这是我的代码:

CGSize s = [string sizeWithFont:[UIFont systemFontOfSize:20]
               constrainedToSize:CGSizeMake(self.view.bounds.size.width - 40, CGFLOAT_MAX) // - 40 For cell padding
                   lineBreakMode:UILineBreakModeWordWrap];

我收到一条警告说 UILinebBreakModeWordWrap 在 iOS 6 中已弃用。

4

2 回答 2

204

您需要NSLineBreakByWordWrapping在 iOS 6中使用

对于您的代码,请尝试以下操作:

NSString *string = @"bla";

CGSize s = [string sizeWithFont:[UIFont systemFontOfSize:20]
              constrainedToSize:CGSizeMake(self.view.bounds.size.width - 40, CGFLOAT_MAX) // - 40 For cell padding
                  lineBreakMode:NSLineBreakByWordWrapping];

标签上的一个例子是:

[label setLineBreakMode:NSLineBreakByWordWrapping];

代替

label.lineBreakMode = UILineBreakModeWordWrap;
于 2012-10-17T09:55:16.640 回答
14

为了保持向后兼容性,您可以创建如下宏:

#ifdef __IPHONE_6_0
# define LINE_BREAK_WORD_WRAP NSLineBreakByWordWrapping
#else
# define LINE_BREAK_WORD_WRAP UILineBreakModeWordWrap
#endif
于 2013-04-29T17:54:33.803 回答