I just had to make a UITableViewCell with automatic height calculation using the method systemLayoutSizeFittingSize:UILayoutFittingCompressedSize
. Until my view had UILabels and UIImageViews, everything worked great. When I needed to replace one of the labels with UIButton, the method did not calculate the size correctly.
Do we need to supply some extra info to UIElements other than UILabels to work properly?
In the end I had to add TapGestures to the UILabels to make it work.
Here is the cell view:
The time "09:00 AM" and location are the labels here, these could have been buttons, if the method gave the result properly.
The idea is simple, create a cell xib with smallest screen size possible (iPhone 3.5 inch). Create a xib instance separately in your class, supply info to that instance (Time, location, etc) and run the systemLayoutSizeFittingSize:UILayoutFittingCompressedSize method to calculate the size.
_scheduleCell = [[[UINib nibWithNibName:@"HomeScheduleViewCell" bundle:nil] instantiateWithOwner:nil options:nil] objectAtIndex:0];
CGSize fullSize = [_scheduleCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];