UILineBreakModeWordWrap is deprecated

UilabelDeprecated

Uilabel Problem Overview


Here's my code:

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

I get a warning that UILinebBreakModeWordWrap is deprecated in iOS 6.

Uilabel Solutions


Solution 1 - Uilabel

You need to use NSLineBreakByWordWrapping in iOS 6

For your code try this:

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];

an example on a label would be:

[label setLineBreakMode:NSLineBreakByWordWrapping];

Instead of

label.lineBreakMode = UILineBreakModeWordWrap;

Solution 2 - Uilabel

To maintain backward compatibility, you can create a macro as below:

#ifdef __IPHONE_6_0
# define LINE_BREAK_WORD_WRAP NSLineBreakByWordWrapping
#else
# define LINE_BREAK_WORD_WRAP UILineBreakModeWordWrap
#endif

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDrakesinmoueView Question on Stackoverflow
Solution 1 - UilabelAndy DaviesView Answer on Stackoverflow
Solution 2 - UilabelMihriban MinazView Answer on Stackoverflow