-
Set the
estimatedItemSize
property of the flow layout to a non-zero value.// Inside the view controller that has controls a collectionView. override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. let flowLayout:UICollectionViewFlowLayout = collectionView.collectionViewLayout as! UICollectionViewFlowLayout flowLayout.estimatedItemSize = CGSizeMake(100, 30) }
-
Use constraints on the collection view cell content view,
or overridesizeThatFits:
.// Inside the custom collection view cell class, override |sizeThatFits:|. override func sizeThatFits(size: CGSize) -> CGSize { return CGSizeMake(*customWidth*, *customHeight*) }
网友评论