繁体   English   中英

如何使用自动布局保持UITableViewCell的宽高比?

[英]How can I keep an aspect ratio of UITableViewCell using Auto layout?

我想使用自动布局保持UITableViewCell的宽高比。 我想将tableViewCell的宽度设置为

UIScreen.mainScreen().bounds.size.width - 10

然后,我想将单元格的高度设置为1.2 *宽度。 如果你知道怎么做,或者一些参考,请告诉我。 谢谢你的好意。

您可以使用UITableViewDelegate协议函数heightForRowAtIndexPath

迅速:

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return tableView.frame.width * 1.2
}

目标C:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return tableView.frame.size.width * 1.2;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM