[英]How can I keep an aspect ratio of UITableViewCell using Auto layout?
I'd like to keep aspect ratio of UITableViewCell using Auto layout. 我想使用自动布局保持UITableViewCell的宽高比。 I want to set the width of a tableViewCell as
我想将tableViewCell的宽度设置为
UIScreen.mainScreen().bounds.size.width - 10
Then, I'd like to set the height of the cell as 1.2*width. 然后,我想将单元格的高度设置为1.2 *宽度。 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
: 您可以使用
UITableViewDelegate
协议函数heightForRowAtIndexPath
:
Swift: 迅速:
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return tableView.frame.width * 1.2
}
Objective C: 目标C:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return tableView.frame.size.width * 1.2;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.