So I am making an app using iOS 6 and was wondering why my code that used to work great on iOS 5 does not work anymore. I have a cell with dynamic UILabel that gets adjusted based on the text that it carries.
This is with autolayout turned on:
This is with autolayout turned off:
Here is my code:
- (CGFloat)heightForText:(NSString *)bodyText
{
#define FONT_SIZE 13.0f
#define CELL_CONTENT_WIDTH 280.0f
#define CELL_CONTENT_MARGIN 5.0f
CGSize constraintSize = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);
CGSize labelSize = [bodyText sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraintSize lineBreakMode:NSLineBreakByWordWrapping];
CGFloat height = MAX(labelSize.height, 36.0f);
// NSLog(@"height=%f", height);
return height + (CELL_CONTENT_MARGIN * 2);
}
- (CGFloat)tableView:(UITableView *)tv heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger section = [indexPath section];
switch (section) {
case 0:
if ([self.text.text length]!=0)
{
return [self heightForText:self.text.text];
}
else if ([self.link.text length]!=0)
{
return 60.0f;
}
}