简体   繁体   English

Swift - 更改 UICollectionViewCell 大小

[英]Swift - change UICollectionViewCell size

I'm struggling to change the size of my UICollectionViewCell programmatically.我正在努力以编程方式更改UICollectionViewCell的大小。

I've tried this:我试过这个:

let columnLayout = FlowLayout(
        itemSize: CGSize(width: 150, height: 150),
        minimumInteritemSpacing: 10,
        minimumLineSpacing: 10,
        sectionInset: UIEdgeInsets(top: 20, left: 20, bottom: 10, right: 20)) 

But that doesn't work for me.但这对我不起作用。 Do I have to call this somewhere?我必须在某个地方打电话吗?

Try尝试

self.collectionView.collectionViewLayout = columnLayout

inside viewDidLoadviewDidLoad里面

lazy var columnLayout:FlowLayout = {
   return FlowLayout(itemSize: CGSize(width:(self.view.frame.width - 40) / 2, height: 150),
    minimumInteritemSpacing: 10,
    minimumLineSpacing: 10,
    sectionInset: UIEdgeInsets(top: 20, left: 20, bottom: 10, right: 20)) 
}()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM