How to nest a UICollectionViewCell inside another

2019-08-20 09:46发布

问题:

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.

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