如何将 UICollectionViewCell 嵌套在另一个中? [英] How to nest a UICollectionViewCell inside another one?

查看:31
本文介绍了如何将 UICollectionViewCell 嵌套在另一个中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按照我的旧问题

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

解决方案

import Foundation导入 UIKit类 ObjCell: UICollectionViewCell{让 leftView: UIView = {让视图: UIView = UIView()view.backgroundColor = UIColor.redview.frame = CGRect(x:20, y:50, width:320, height:50)view.translatesAutoresizingMaskIntoConstraints = false返回视图}()覆盖初始化(框架:CGRect){super.init(框架:框架)setCellUI()}需要初始化?(编码器aDecoder:NSCoder){fatalError("init(coder:) 尚未实现")}func setCellUI(){backgroundColor = UIColor.yellow添加子视图(左视图)}}

Following my old question here: How to add UIView inside a UITableViewCell Programmatically?

I wanna achieve an enhanced view like that of iOS 11 Today tab with adding more elements in those collectionViewCell cards.

I want to add biDirectional Scrolling like that of Netflix or other AppStore tabs(Games & Apps) inside my CollectionViewCell card(App Store Today tab cells). Here is an overview of what I want:

Please tell is it possible to achieve such thing. If yes then how? Thanks.

解决方案

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) 
}
}

这篇关于如何将 UICollectionViewCell 嵌套在另一个中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆