ios - 使用 Autolayout 时,单元格高度会随着设备高度的变化而变化吗?

标签 ios uitableview autolayout height cell

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

最佳答案

Autolayout 无法做到这一点。您应该以编程方式执行此操作,但这非常简单。 您必须从 UITableviewDelegate 实现一个“方法”:

- tableView:heightForRowAtIndexPath:

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

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

关于ios - 使用 Autolayout 时,单元格高度会随着设备高度的变化而变化吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32454662/

相关文章:

swift - 如何在编辑 tableView 后更新模型

iphone - ios 6 : Center UILabel vertically using Auto Layout constraints

ios - 使用 error.code 处理 NSError

ios - 这是为性能设置属性的首选方式

ios - UITableView 中的 NSRangeException

ios - 刷新时数组索引超出范围

ios - 为 Flutter App 自定义 BottomNavigationBar selected BottomNavigationBarItem

ios - 您的二进制文件中不存在应用内购买功能

ios - UILabel 子类在使用约束时不显示

ios - 使具有动态高度 subview 的 UIScrollView 自动与自动布局一起工作