如何在Swift中以编程方式更改UICollectionViewCell大小? [英] How to change UICollectionViewCell size programmatically in Swift?
问题描述
我有一个 UICollectionView
,带有分段控件
来切换数据。但是如何以编程方式更改 UICollectionViewCell
尺寸属性?然后我可以为每种数据类型适当地定制每种样式。
I have a UICollectionView
with a segmented control
to switch between data. But how do I change the UICollectionViewCell
size properties programmatically ? then I can custom each style appropriately for each data type.
例如将宽度更改为520点,将高度更改为100.我是iOS开发新手,对CSS很有经验:/
For example change the width to 520 points and height to 100. I am new to iOS development and am experienced with CSS :/
我知道如何在Xcode中做(显然),但不知道在swift中更改它的正确方法。任何想法或反馈都非常感谢(Y)
I know how to do it in Xcode (obviously) but do not know the correct methods to change it in swift. Any ideas or feedback is much appreciated (Y)
推荐答案
//Use for size
func collectionView(collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
}
//Use for interspacing
func collectionView(collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
minimumInteritemSpacingForSectionAtIndex section: Int) -> CGFloat {
return 1.0
}
func collectionView(collectionView: UICollectionView, layout
collectionViewLayout: UICollectionViewLayout,
minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat {
return 1.0
}
//对于swift 3
// For swift 3
func collectionView(_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAt indexPath: IndexPath) -> CGSize {
}
func collectionView(_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return 1.0
}
func collectionView(_ collectionView: UICollectionView, layout
collectionViewLayout: UICollectionViewLayout,
minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 1.0
}
这篇关于如何在Swift中以编程方式更改UICollectionViewCell大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!