【问题标题】:how to fit collection view cell in table view cell ( adaptive on all screen sizes?)如何在表格视图单元格中适合集合视图单元格(适用于所有屏幕尺寸?)
【发布时间】:2020-10-04 06:11:16
【问题描述】:

我的集合视图单元格(7 个单元格)需要适合表格视图单元格,但是当我运行它时,它在 iPhone 6 和 iPhone X 中的显示不同。 有什么办法可以解决这个问题吗?

假设我有 2 个集合视图,它们应该覆盖并适应不同的设备屏幕尺寸。

【问题讨论】:

  • 您能否发布 2 部不同手机上的布局照片和理想布局的照片?

标签: ios swift xcode ios-autolayout


【解决方案1】:

在您的自定义 UITableViewCell 中

 override func systemLayoutSizeFitting(_ targetSize: CGSize, withHorizontalFittingPriority horizontalFittingPriority: UILayoutPriority, verticalFittingPriority: UILayoutPriority) -> CGSize {
    self.contentView.frame = self.bounds
    self.contentView.layoutIfNeeded()
    self.collectionView.reloadData()
    return self.collectionView.contentSize
}

当你配置单元格时,意味着你正在将数据从控制器传递到你的 UITableViewCell 中使用它

self.collectionView.layoutIfNeeded()
self.contentView.layoutIfNeeded()

【讨论】:

  • 有没有其他方法可以在没有 UItableViewCell 实例的静态表格视图中使用它?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-24
  • 1970-01-01
  • 2017-09-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多