FlowLayout
flowLayout.estimatedItemSize = UICollectionViewFlowLayoutAutomaticSize
collectionViewCell
class CollectionViewCell: UICollectionViewCell {
@IBOutlet weak var titleLabel: UILabel! {
didSet {
titleLabel.text = nil
}
}
@IBOutlet weak var textLabel: UILabel! {
didSet {
textLabel.text = nil
}
}
@IBOutlet weak var separator: UIView!
@IBOutlet weak var widthLayout: NSLayoutConstraint?
override func awakeFromNib() {
super.awakeFromNib()
// 本当は CollectionView の幅とかを指定したほうが良い
setCellWidth(UIScreen.main.bounds.width)
}
func setCellWidth(_ width: CGFloat) {
widthLayout?.constant = width
}
class func nib() -> UINib {
return UINib(nibName: "\(self)", bundle: nil)
}
override func prepareForReuse() {
super.prepareForReuse() // Don't forget!
}
}