I'd like to keep aspect ratio of UITableViewCell using Auto layout. I want to set the width of a tableViewCell as
UIScreen.mainScreen().bounds.size.width - 10
Then, I'd like to set the height of the cell as 1.2*width. If you know how to do it, or some references, please tell me. Thank you for your kindness.
You can use UITableViewDelegate protocol function heightForRowAtIndexPath:
Swift:
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return tableView.frame.width * 1.2
}
Objective C:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return tableView.frame.size.width * 1.2;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With