Created
August 13, 2014 17:46
-
-
Save jeffbailey/971b651ee588657ee2bf to your computer and use it in GitHub Desktop.
iOS 8 Resizable Table View Cells and multiline labels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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