UILabel text alignment to centre in collectionView iOS 6 for multiple lines

703 views Asked by At

I'm using a UILabel in collection view cell which is centre aligned and has multiple lines. I'm using adjustFontSizeToFitWidth = YES and minimumFontScale = 0.5 to reduce the font size when text does not fit. This works fine in iOS 7.

But in iOS 6 the text alignment goes to the left. To align it to centre I used adjustLetterSpacingToFitWidth = NO which I found in other threads, this aligns the text to centre but the text doesn't fit and leaves a "..." trail in the end.

Thanks for the help!

2

There are 2 answers

2
Wyetro On

You could use a UITextView which will allow you to wrap the text, unlike the UILabel. If you want all of your text on one line you could make it so that in iOS 7 the text is shrunk one amount and in iOS 6 it is shrunk more.

1
ambreesh kushwaha On

Now UILabel has [textLabel sizeToFit]; for label size changing also you can use following code:

textLabel.adjustsFontSizeToFitWidth = YES;

textLabel.numberOfLines = 0;

[textLabel sizeToFit];