不推荐使用UILineBreakModeWordWrap

Dra*_*oue 82 deprecated uilabel

这是我的代码:

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

我收到一条警告,在iOS 6中不推荐使用UILinebBreakModeWordWrap.

And*_*ies 202

你需要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];
Run Code Online (Sandbox Code Playgroud)

标签上的一个例子是:

[label setLineBreakMode:NSLineBreakByWordWrapping];
Run Code Online (Sandbox Code Playgroud)

代替

label.lineBreakMode = UILineBreakModeWordWrap;
Run Code Online (Sandbox Code Playgroud)

  • 啊,小事 (3认同)

Mih*_*naz 14

要保持向后兼容性,您可以创建一个宏,如下所示:

#ifdef __IPHONE_6_0
# define LINE_BREAK_WORD_WRAP NSLineBreakByWordWrapping
#else
# define LINE_BREAK_WORD_WRAP UILineBreakModeWordWrap
#endif
Run Code Online (Sandbox Code Playgroud)