Skip to content

Instantly share code, notes, and snippets.

@jeffbailey
Created August 13, 2014 17:46
Show Gist options
  • Save jeffbailey/971b651ee588657ee2bf to your computer and use it in GitHub Desktop.
Save jeffbailey/971b651ee588657ee2bf to your computer and use it in GitHub Desktop.
iOS 8 Resizable Table View Cells and multiline labels
A good blog post and sample project is at:
https://github.com/kharrison/CodeExamples/tree/master/SelfSize
UITableViewController Methods:
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 100.0f;
}
// As of iOS 8 Beta 5 you need to reload the table data on viewDidAppear. YUK...
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
// [self.tableView reloadData];
}
UITableViewCell Methods:
- (void)layoutSubviews
{
[super layoutSubviews];
[self.contentView layoutIfNeeded];
self.lineLabel.preferredMaxLayoutWidth = CGRectGetWidth(self.lineLabel.frame);
}
Storyboard:
Set the number of lines to 0 for the UILabel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment