[英]Keep aspect ratio of an UIImageView in a custom 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.