I'm working on a ios app minimum ios 5 and i have just hit a weird issue with uilabels. or maybe im missing something obvious. anyway the problem im having is that i have a uilabel which is to be centered text aligned. all works fine on ios 5 but on ios 6 it is always is left aligned. I seen that the old way of doing uilabel text align has deprecated and that setting it as so should work.
self.topComment.textAlignment = NSTextAlignmentCenter;
But no even this way it still only is center aligned on ios 5 and left aligned on ios 6. I do have some code that resizes the font of the text in the label to try make it fit with a min and max size.
UIFont *font = self.topComment.font;
for(int i = maxFont; i > minFont; i--)
{
// Set the new font size.
font = [font fontWithSize:i];
CGSize constraintSize = CGSizeMake(self.topComment.frame.size.width, 1000);
CGSize labelSize = [topString sizeWithFont:font constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
if(labelSize.height <= self.topComment.frame.size.height ) {
fits = YES;
break;
}
//self.topComment.text = topString;
}
self.topComment.font = font;
self.topComment.text = topString;
So that is the only thing i am doing to the label but it always is left aligned in ios 6. Important to note that if i drop in a uilabel with text and center align it and dont use the above code then it is centered on both ios 5 and 6.