Reputation: 315
Here is how my app look right now, please excuse the ugly pink it's used for debugging purposes:
As you can see, all the cells are the same size and the UIImageViews are also the same size but the image doesn't fill it all up. Ideally, I want all the photos to have the same width but varying heights depending on the photo, and for each cell to be sized accordingly because some photos are taller than others and I don't want short photos to take up space.
Here are my storyboard and constraints:
The people I've asked for help with this have told me to do it programmatically. I've googled extensively and am still unsure how to do this, already tried image.frame.width = 100 but that didn't do anything. Is there a way to do this on Storyboard and if not, how do I do this programmatically (in Swift please!)?
Thank you!
Upvotes: 0
Views: 229
Reputation: 384
Try this one:
override func viewDidLoad() {
super.viewDidLoad()
// Default cell height
self.tableView.estimatedRowHeight = 60
// This will auto increment your table cell height
self.tableView.rowHeight = UITableViewAutomaticDimension
}
Upvotes: 1
Reputation: 116
There are three ways:
1.Manually calculate all the images' heights before the pre-rendering and pass the heights to the tableview delegate.
2.use UITableViewAutomaticDimension property for self-sizing cell, it need use auto-layout and system version need higher than 8.0.
3.As the previous way, there is a excellent third party library for auto resizing cells which named UITableView-FDTemplateLayoutCell. It support iOS6+.
Upvotes: 0