设想:
我有一个 custom UITableViewCell
,我在UIImageView
里面添加了一个。我可以添加width
, height
, top
, bottom
, trailing
, leading
,center vertically/horizontally
constraints
但我想为宽高比添加约束。Storyboard 不允许我使用UITableViewCell 的 Content View添加纵横比约束,因此为了克服它,我添加了另一个具有约束顶部、底部、尾随、前导(常量 = 0)UIImageView
的视图,然后对其进行了子视图并添加了纵横比约束。之后我提到了细胞的高度使用
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 60; // for example
}
这工作正常。
问题: 这是好方法还是有另一种方法来解决相同的场景?
PS:我会添加截图,但论坛不让我