I have been using this code for quite a long time in my iOS 5/6 apps. It's under viewWillAppear:
and manipulates a UILabel
height do that it can fit more text in as needed (and pushes other labels below it down). The problem is, with iOS 7, it doesn't appear to be working anymore. The text simply doesn't wrap to the second line. Here is the code:
self.titleLabel.text = titleString;
self.titleLabel.lineBreakMode = NSLineBreakByWordWrapping;
self.titleLabel.numberOfLines = 0;
// Determine what the size of the title label should be
CGSize maximumLabelSize = CGSizeMake(163,66);
CGSize expectedLabelSize = [titleString sizeWithFont:self.titleLabel.font
constrainedToSize:maximumLabelSize
lineBreakMode:self.titleLabel.lineBreakMode];
// Adjust the the new height of the title label.
CGRect newFrame = self.titleLabel.frame;
newFrame.size.height = expectedLabelSize.height;
self.titleLabel.frame = newFrame;
NSLog(@"Title Height: %f", self.titleLabel.frame.size.height);
Here's a bit more information. This UILabel
is on a header view in a UITableView
. It's designed with Interface Builder and an IBOutlet
to the label. The properties of the UILabel
are identical between both the iOS 6 and iOS 7 project.
Here is what is looks like with Xcode 4 running against iOS 6:
And here is Xcode 5 with iOS 7 (as you can see, the text doesn't wrap down):
Anyone have any ideas?