1

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!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
allwynmasc
  • 393
  • 5
  • 18

2 Answers2

0

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.

Wyetro
  • 8,439
  • 9
  • 46
  • 64
  • the shrunking text part did not work in iOS 6.1 and like I said in ios7 it works fine so i wouldn't want to switch to textview now. Could this be some sort of bug in ios6 itself that it doesn't work? – allwynmasc Jul 22 '14 at 09:04
  • You could always make it so the minimum iOS required is iOS 7. – Wyetro Jul 22 '14 at 13:03
0

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

textLabel.adjustsFontSizeToFitWidth = YES;

textLabel.numberOfLines = 0;

[textLabel sizeToFit];