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

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

问题描述

我有 ViewController 和其中的 CollectionView.我想通过按下按钮更改 CollectionView 插图.我应该实现什么代码?

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

谢谢!

推荐答案

设置section inset,使布局失效.

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天全站免登陆