简体   繁体   English

如何在表格视图单元格中放置集合视图单元格(适用于所有屏幕尺寸?)

[英]how to fit collection view cell in table view cell ( adaptive on all screen sizes?)

My collection view cells (7 cells) need to fit into table view cell, but when I run it it shows differently in iPhone 6 and iPhone X. Is there any way that I can overcome the issue?我的集合视图单元格(7 个单元格)需要适合表格视图单元格,但是当我运行它时,它在 iPhone 6 和 iPhone X 中的显示不同。有什么办法可以克服这个问题吗?

在此处输入图像描述 Let's say I have 2 collection views which should cover and fit adaptively on different device screen sizes.假设我有 2 个集合视图,它们应该覆盖并适应不同的设备屏幕尺寸。

In your custom UITableViewCell在您的自定义 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
}

and when u are configuring the cell means u are passing data From controller to your UITableViewCell use this in that当你正在配置单元格时,意味着你正在将数据从 controller 传递到你的 UITableViewCell 使用这个

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将集合视图单元格设置为所有屏幕的相等行单元格 - how to set collection view cell as equal row cell for all screen 使用“自动布局”更新集合视图高度以适合表视图单元格中的所有单元格 - Update collection view height to fit all cells within a table view cell using Auto Layout iOS:自适应集合视图单元格宽度 - iOS : Adaptive Collection View cell width 如何通过快速点击集合视图的单元格在表视图中重新加载数据 - How to reload data in table view by tapping the cell of collection view in swift 来自笔尖的表格视图单元格中的集合视图 - Collection view in table view cell from nib 表视图单元格内的集合视图 - Collection View inside Table View Cell 如何在表格视图单元格内创建集合视图 - How to create collection view inside table view cell 如何在Swift 3中实现表格视图单元格嵌入集合视图? - How to implement a table view cell embed collection view in swift 3? 在swift 3中单击另一个表视图单元格的集合视图数据后,如何在表视图单元格中重新加载集合视图数据? - How to reload the collection view data in table view cell after clicking another table view cell's collection view data in swift 3? 自定义表格单元格未调整大小以适应内容视图 - Custom table cell not resizing to fit content view
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM