在 Swift 中以编程方式将插图设置为 CollectionView [英] Set insets to the CollectionView programmatically in Swift

查看:24
本文介绍了在 Swift 中以编程方式将插图设置为 CollectionView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 ViewControllerCollectionView 在里面.我想通过按下按钮来更改 CollectionView 插图.我应该实现什么代码?

I have ViewController with the CollectionView in it. I want to change CollectionView insets by pressing button. What code I should implement?

谢谢!

推荐答案

设置节插入并使布局无效.

Set the section inset and invalidate the layout.

let collectionViewLayout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout

collectionViewLayout?.sectionInset = ... // some UIEdgeInset

collectionViewLayout?.invalidateLayout()

这篇关于在 Swift 中以编程方式将插图设置为 CollectionView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆