Question

I am trying to write 4 lines in UILabel so I put 0 for numberoflines in editor.

Below is what I have in ViewController

enter image description here

When I run in iOS6

enter image description here

When I run in iOS7

enter image description here

If you see, for iOS 6, I get three lines only. Any idea why this is happening?

How can I have 4 lines in iOS 6?

Was it helpful?

Solution

This is weird...

[introText sizeToFit]; did the trick

OTHER TIPS

as i wrote in comment, some weeks ago i had the same problem, and this is my solution, i set line spacing to paragraphStyle different based on systemVersion:

 NSString *ver = [[UIDevice currentDevice] systemVersion];
 int ver_int = [ver intValue];

 if (ver_int < 7) {

    NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
    [paragraphStyle setLineSpacing: 10]; //set line spacing what you what

    NSDictionary *attributes = @{ NSFontAttributeName: labelText.font, NSParagraphStyleAttributeName: paragraphStyle };
    NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:labelText.text attributes:attributes];

    [labelText setAttributedText: attributedString];

 } else {

    NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
    [paragraphStyle setLineSpacing: 5];

    NSDictionary *attributes = @{ NSFontAttributeName: labelText.font, NSParagraphStyleAttributeName: paragraphStyle };
    NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:labelText.text attributes:attributes];

    [labelText setAttributedText: attributedString];
 }

Are you using an attributed string to adjust the line spacing? There were lots of bugs related to attributed strings in iOS6, especially relating to line heights and paragraph spacing.

Many of these bugs would show up if you tried using multiple different attributes in the same attributed string - on their own, they would render correctly.

There are going to be differences between iOS6 and iOS7 due to all the UI and font changes. My guess is that the height of the control in iOS6 is slightly too small (perhaps by a single point) and therefore the control cannot wrap even though it wants too. Try expanding the height slightly and see if it fixes the problem. You might have to used the methods for calculating a CGSize that formatted text will go into in order to work out how high to make the control.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top