Ok so heres my dilemma, I have a block of code that works great, its deprecated but it calculates the appropriate size of the height of any block of text. (Below works but deprecated)
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0 && indexPath.row == 2) {
CGSize size = [[item desc] sizeWithFont:[UIFont systemFontOfSize:17] constrainedToSize:CGSizeMake(290 - (10 * 2), 200000.0f)];
CGFloat height = MAX(size.height, 44.0f);
return height + (2 * 2);
}
return 44;
}
Trying to remove deprecated code so I've been stuck on the proper way to fix it for a few days now and I came up with this.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0 && indexPath.row == 2) {
NSStringDrawingContext *ctx = [NSStringDrawingContext new];
NSAttributedString *aString = [[NSAttributedString alloc] initWithString:[item desc]];
UITextView *calculationView = [[UITextView alloc] init];
[calculationView setAttributedText:aString];
CGRect textRect = [calculationView.text boundingRectWithSize:self.view.frame.size options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:calculationView.font} context:ctx];
CGFloat height = MAX(textRect.size.height, 44.0f);
return height + (2 * 2);
}
return 44;
}
This certainly does not work it works from a code level standpoint but it does not size the cell appropriately. I feel like this should be easy any help appreciated.
Try this:
You have not provided required size constraint as you were providing in deprecated method.. That's why you are not getting desired output..