I am working on UITableView and the cells have different contents like a Facebook cell, so how can i change the height of each cell accordingly?
Asked
Active
Viewed 100 times
-8
-
1use `heightForRowAtIndexPath:` – ChintaN -Maddy- Ramani Feb 16 '15 at 05:34
-
3Possible duplicate of http://stackoverflow.com/questions/18527227/uitableviewcell-with-dynamic-height-ios U need to do some googling before posting out question... – Vidhyanand Feb 16 '15 at 06:07
2 Answers
0
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
UIFont *font = [UIFont systemFontOfSize:20];
NSDictionary *userAttributes = @{NSFontAttributeName: font,
NSForegroundColorAttributeName: [UIColor blackColor]};
NSString *text = @"Your label text";
CGSize textSize = [text sizeWithAttributes: userAttributes];
ht = 20;
if (textSize.width > [FunctionUtils getViewWidth]) {
ht = (textSize.width/([FunctionUtils getViewWidth]));
ht = (ceil(ht))*20+35;
//20 font size
}
return ht;
}

yoshiiiiiiii
- 953
- 8
- 20
0
You Should follow the link http://www.raywenderlich.com/73602/dynamic-table-view-cell-height-auto-layout This is best way to achieve to do this

Nirmal Choudhari
- 559
- 5
- 17