I have label in a cell, when I click on a cell I want to cell increases as much as the size of label. Currently my code resizes the cell to 240.
My label:
UILabel *cellLabel3 = (UILabel *)[cell viewWithTag:5];
[cellLabel3 setText:[Data objectAtIndex:self.expandedIndexPath.row]];
Code for cell height:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([indexPath compare:self.expandedIndexPath] == NSOrderedSame) {
return 240;
}
return 90.0;
}
Try this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
self.expandedIndexPath = indexPath;
[self.tableView reloadData];
}
This Question has answer already But still posting answer,
Calculate Height of Text from method
CGSize maximumSize = CGSizeMake(kLabelWidth, CGFLOAT_MAX);
CGSize size = [text sizeWithFont:font
constrainedToSize:maximumLabelSize
lineBreakMode:UILineBreakModeWordWrap];
And replace kLabelWidth with label width & font with your label font and return size.height
from heightForRowAtIndexPath.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.