Reputation: 1658
I want to dynamically increase the height of tableview cell according to Content of textview in cell. Here I create textview and add that textview in cell as subview. So according to content of textview height of tableview cell is get fixed. Any one know how to do that.
Thanks in advance
Upvotes: 1
Views: 1281
Reputation: 491
-(CGFloat) tableView: (UITableView *) tableView heightForRowAtIndexPath: (NSIndexPath *) indexPath{
CGSize labelSize = CGSizeMake(200.0, 20.0);
NSString *strTemp = @"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";
if ([strTemp length] > 0)
labelSize = [strTemp sizeWithFont: [UIFont boldSystemFontOfSize: 14.0] constrainedToSize: CGSizeMake(labelSize.width, 1000) lineBreakMode: UILineBreakModeWordWrap];
return (labelSize.height + 10);
}
Upvotes: 0
Reputation: 8053
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
int rowHeight =0.0f;
NSString *temp = @"bqDHJIGQ BQWFVHWEF Q dsbkn w jwh ndbvdhqd bdhjqdv dqvhdqvb dbqvwvhdqwwd bqwdhjvqwdhjvqwd bqdwjhqwdvbqwd q dbdqwqbvqwdvdw qwdhqwdvbqw dbqvwdjqwd dwbvvqjwd nqdjqvdjqw dwnqwdjvqhdq nwwdjqwvdhjqwd qwdhjvhvbjd n qhjdvqdw dbqw wbdww.";
CGSize size = [temp sizeWithFont:[UIFont systemFontOfSize:13.0f] constrainedToSize:CGSizeMake(300, 5000) lineBreakMode:UILineBreakModeWordWrap];// calculate the height
rowHeight = size.height+10; // i use 10.0f pixel extra because depend on font
return rowHeight;
}
Upvotes: 6