【问题标题】:Width of UICollectionView doesn't change inside UITableViewCellUICollectionView 的宽度在 UITableViewCell 内没有改变
【发布时间】:2021-03-25 23:31:08
【问题描述】:

我在 UITableViewCell 中有 UICollectionView。如果我将 CollectionviewCell 的大小设置为 custom 并提供固定宽度,那么它可以正常工作。

但如果我将其设为 自动 并在委托中分配大小,则它不起作用。它采用默认宽度,即 50。

你能帮帮我吗? 谢谢

改变大小的代码:

extension BeInspiredTVC : UICollectionViewDelegate , UICollectionViewDelegateFlowLayout{

    
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        

        return CGSize(width: UIScreen.main.bounds.width - 50, height: 224)
    }

}

我想要一个全宽的 Collectionviewcell,但我得到了如下图所示。

【问题讨论】:

  • 您能否通过图片展示您需要实现的目标
  • 是的。当然。让我编辑问题。
  • 请查看问题中的图片
  • 可以添加更改大小的代码
  • 已添加。请检查。

标签: ios swift uitableview uicollectionview storyboard


【解决方案1】:

采取集合视图宽度约束

接下来将 self.contentView.frame.width 分配给 tableview 单元格中 layoutsubsview 中的该约束。

【讨论】:

  • 感谢您的回复。实际上 CollectionView 的宽度很好,但是如果我将其设为自动,则 CollectionviewCell 的宽度不会改变。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-07-30
  • 1970-01-01
  • 2021-02-22
  • 1970-01-01
  • 1970-01-01
  • 2021-05-18
  • 1970-01-01
相关资源
最近更新 更多