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

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

问题描述

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

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).

任何帮助都将非常感激。

Any help will be really appreciated.

推荐答案

简单回答:

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