contentViewを使わないとダメらしい。
class MyCollectionViewCell: UICollectionViewCell {
let image = UIImageView()
override init(frame: CGRect) {
super.init(frame: frame)
picture.frame = contentView.frame
self.contentView.addSubview(picture)
}
ダメな例だと同じセルが沢山出たり、背景色だけで何も出なかったりして悲惨なことになります。
非常に分かりにくくてはまったorz
ストーリーボード経由でやってる人にはあんまし縁のない話かとは思います。
これはダメな例
class MyCollectionViewCell: UICollectionViewCell {
let image = UIImageView()
override init(frame: CGRect) {
super.init(frame: frame)
picture.frame = frame
self.addSubview(picture)
}