【发布时间】:2017-05-30 17:01:25
【问题描述】:
我正在使用带有默认 UICollectionViewFlowLayout 的 UICollectionView:
let layout = UICollectionViewFlowLayout()
layout.estimatedItemSize = UICollectionViewFlowLayoutAutomaticSize
cv = UICollectionView(frame: .zero, collectionViewLayout: layout)
我的自定义单元格是:
class CVLegislationCell : UICollectionViewCell {
let card = CardView() // A view that uses auto layout
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}
func setup()
{
self.contentView.addSubview(card)
card.constrain_edges(to: contentView) // convenience function I wrote for auto layout
}
}
由于某种原因,我得到了各种自动布局错误,并且尺寸错误。我的子类化不正确吗?
【问题讨论】:
-
您需要将
layout.estimatedItemSize设置为实际值
标签: ios swift uicollectionview autolayout