I tried to make a programatically view inside UICollectionViewCell, and I think it will be wise to put the "programatically view code" inside UICollectionViewCell.
So here is my code:
override func awakeFromNib() {
super.awakeFromNib()
let view = UIView()
view.frame = CGRect.zero
view.backgroundColor = UIColor.black
self.contentView.addSubview(view)
self.contentView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
view.topAnchor.constraint(equalTo: self.contentView.topAnchor, constant: 0),
view.bottomAnchor.constraint(equalTo: self.contentView.bottomAnchor, constant: 0),
view.trailingAnchor.constraint(equalTo: self.contentView.trailingAnchor, constant: 25),
view.leadingAnchor.constraint(equalTo: self.contentView.leadingAnchor, constant: 25),
])
self.contentView.layoutIfNeeded()
}
I was wondering why the auto layout does not work, instead if I use manual CGRect, the view did appeared.