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

lal*_*ala 2 uitableview ios autolayout swift

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

UIScreen.mainScreen().bounds.size.width - 10
Run Code Online (Sandbox Code Playgroud)

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

Vit*_*nko 9

您可以使用UITableViewDelegate协议功能heightForRowAtIndexPath:

迅速:

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

目标C:

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