【问题标题】:Cell height changes as device height changes using Autolayout?单元格高度随着使用自动布局的设备高度变化而变化?
【发布时间】:2015-12-03 22:53:04
【问题描述】:

在 iPhone 5s 的屏幕尺寸中,我的行高为 80 px,但是当表格出现在 iPhone 6+ 上时,它与 iPhone 5s 的相同。可以使用Auto layout调整单元格的高宽比吗?

【问题讨论】:

  • 我不认为表格视图中的自动布局效果。在 iOS7 上,如果您尝试使用自动布局将子视图添加到表格视图,您甚至会崩溃。您可以使用 setRowHeight 根据不同的手机大小设置不同的值
  • 尝试根据不同的屏幕尺寸在heightForRowAtIndexPath方法中设置高度。

标签: ios uitableview autolayout height cell


【解决方案1】:

Autolayout 无法做到这一点。您应该以编程方式进行,但这很容易。 你必须从UITableviewDelegate 实现一个“方法”:

- tableView:heightForRowAtIndexPath:

并根据设备屏幕高度设置单元格高度。例如:

- (CGFloat)tableView:(UITableView *)tableView  heightForRowAtIndexPath:(NSIndexPath *)indexPath {
   return UIScreen.mainScreen.bounds.size.height/7;
}

【讨论】:

  • 感谢您的写作,但我一直在寻找使用代理的自动布局。
  • 好的,然后看看这篇文章。我想对你有帮助:captechconsulting.com/blogs/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-12-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多