I am using custom tableview cell with three labels title,date and description, now I am getting data from web-services, in which some description text is too big to adjust within description label's frame
how to proceed with it ?
I am using custom tableview cell with three labels title,date and description, now I am getting data from web-services, in which some description text is too big to adjust within description label's frame
how to proceed with it ?
simply use like
ObjectiVe-C
- (void)viewDidLoad
{
...
...
self.tableView.estimatedRowHeight = 100.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;
}
Swift
override func viewDidLoad() {
self.tableView.estimatedRowHeight = 80
self.tableView.rowHeight = UITableViewAutomaticDimension
}
ObjectiVe-C
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 80; // customize the height
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewAutomaticDimension;
}
Swift
func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return 80 // customize the height
}
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
finally set your label.numofLines = 0 in attribute or programtically
I would like to know why to know you're looking for a method without using autolayout. I believe previous posted answers are solutions using autolayout
self.tableView.estimatedRowHeight = 50;
self.tableView.rowHeight = UITableViewAutomaticDimension;
and you can set multiline label to expand according to the content of the label
Without autolayout you need to calculate height for each cell (height for each labels + margins) individually and return the value in UITableView datasource method - tableView:heightForRowAtIndexPath:
.
write to viewDidLoad
tableView.estimatedRowHeight = 50
tableView.rowHeight = UITableViewAutomaticDimension
Thanks but issue is not resolved Please check images
Before without using above solutions My table view looks better but text is not adjusted
after using your help
using self.tableView.rowHeight = UITableViewAutomaticDimension;
and heightforcell
method everything is messed
My tableview with storyboard please check size inspector tab for autoresizing section
Whats the wrong am i doing here ?