【问题标题】:How to nest a UICollectionViewCell inside another one?如何将 UICollectionViewCell 嵌套在另一个中?
【发布时间】:2018-09-06 10:40:38
【问题描述】:

按照我的老问题here:How to add UIView inside a UITableViewCell Programmatically?

我想通过在这些 collectionViewCell 卡片中添加更多元素来实现类似于 iOS 11 Today 选项卡的增强视图。

我想在我的 CollectionViewCell 卡(App Store Today 标签单元格)中添加双向滚动,类似于 Netflix 或其他 AppStore 选项卡(游戏和应用程序)。这是我想要的概述:

请告诉是否有可能实现这样的事情。如果是,那怎么办? 谢谢。

【问题讨论】:

  • 创建一个垂直的 CollectionView。对应的 CollectionViewCell 应该是继承自 UICollectionView 的自定义视图。使用自定义视图作为您的电影容器。就是这样。如果您遇到问题,请继续努力并回复问题,但不要指望有人在没有先尝试的情况下为您编写所有代码。
  • 您可以使用UITableViewUITableViewSectionUITableViewCell 进行垂直滚动。还有UITableViewCellUICollectionView 及其UICollectionViewCell
  • 感谢您的帮助。显然,我只是想知道方法,我不是要代码。我知道道德。不管怎样,谢谢! @regina_fallangi
  • 请避免亲自接受表扬。很多人,当新手时,不知道首先必须尝试SO。写演讲听起来可能比实际意思更刺耳。
  • @PratikSodha 伙计,你让我很困惑。在清除了我对此的疑问后,我提出了这个问题(我的老问题)[stackoverflow.com/questions/52201273/…

标签: ios swift xcode uicollectionview uicollectionviewcell


【解决方案1】:
import Foundation
import UIKit

class ObjCell: UICollectionViewCell{

let leftView: UIView = {
    let view: UIView = UIView()
    view.backgroundColor = UIColor.red
view.frame = CGRect(x:20, y:50, width:320, height:50)
    view.translatesAutoresizingMaskIntoConstraints = false
    return view
}()

override init(frame: CGRect) {
    super.init(frame: frame)

    setCellUI()
}

required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}

func setCellUI(){

    backgroundColor = UIColor.yellow
    addSubview(leftView) 
}
}

【讨论】:

  • 您应该始终为您的代码添加一些解释。只给一个sn-p是不好的。
  • 兄弟这是一个 CollectionViewCell 类在这里你可以看到如何以编程方式添加 UIView....?
猜你喜欢
  • 2015-02-07
  • 2021-06-08
  • 2023-03-26
  • 1970-01-01
  • 1970-01-01
  • 2023-04-02
  • 1970-01-01
  • 1970-01-01
  • 2019-11-09
相关资源
最近更新 更多