Search code examples
iosuitextviewlineline-breaks

UITextView line break not working in iOS 7 - works fine in iOS 6


I have a case where text in a UITextView is not line broken correctly in iOS 7. It works fine in iOS 6. The text view, self.textLabel (not the best of variable names but I'm stuck with it), is defined in IB (w:120 h:42 & System Font 13) and populated in the following code:

- (id)initWithIcon:(UIImage*)icon labelText:(NSString*)labelText;
{
    self = [super initWithClass:[self class]];

    self.textLabel.text = [labelText uppercaseString];
    [self.button setImage:icon forState:UIControlStateNormal];

    return self;
}

Links to explanatory screens shots below.

The following texts work fine (in iOS 6 & iOS 7):

"ACCESSOARER & KOSMETIKA" result in: Line 1:"ACCESSOARER &" Line 2:" KOSMETIKA "

"ELEKTRONIK & TELEFONI" result in: Line 1:" ELEKTRONIK & " Line 2:" TELEFONI "

But this text:

RESOR & TRANSPORT results in "SOR & TRANSPO" in iOS 7.

In iOS 6 it results in Line 1: " RESOR & " Line 2:" TRANSPORT "

iOS 6 screenshot

iOS 7 screen shot


Solution

  • This was finally resolved after I filed a Bug Report. I had defined a category on UILabel where I was overriding (CGSize)intrinsicContentSize. So problem disappeared after removing the category. And nothing else broke - makes me wonder why I had put in that category :)

    Apple answer:

    This is happening because you have a category on UILabel and are overriding:

    -(CGSize)intrinsicContentSize {
       CGSize s = [super intrinsicContentSize];
       s = CGSizeMake(s.width, s.height + 4);
       return s;
    }