如何将集合视图单元格大小设置为与 iOS 中的集合视图完全相同? [英] How to set the collection view cell size exactly equal to the collection view in iOS?

查看:9
本文介绍了如何将集合视图单元格大小设置为与 iOS 中的集合视图完全相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置一个集合视图,它一次只显示一个元素并水平滚动.我想知道如果集合视图与超级视图具有相同的宽度(手机大小),如何为两者设置相同的大小.

I want to set a collection view where it is only displayed one element at the time and it scrolls horizontally. I want to know how to set the same size for both if the collection view has equal width with the superview (phone size).

任何帮助将不胜感激.

推荐答案

简单回答:

UICollectionViewDelegateFlowLayout 添加到您的班级然后使用这个方法:

Add UICollectionViewDelegateFlowLayout to your class and then use this method:

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
    return CGSize(width: yourCollectionView.bounds.width, height: yourCollectionView.bounds.height)
}

使其水平:

这篇关于如何将集合视图单元格大小设置为与 iOS 中的集合视图完全相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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