UICollectionView标头宽度 [英] UICollectionView header width

查看:144
本文介绍了UICollectionView标头宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的UICollectionViewFlowLayout子类中,我有以下内容:

In my UICollectionViewFlowLayout subclass I have this:

self.headerReferenceSize = CGSizeMake(280, 44);

但是,标题的显示宽度为320,这是集合视图的宽度.根据文档,这是正确的:

However the header is displayed with a width of 320, which is the width of the collection view. This is correct according to the docs:

在布局期间,仅对应于适当大小的尺寸 使用滚动方向.例如,对于垂直滚动 方向,则布局对象使用由您返回的高度值 方法. (在这种情况下,标头的宽度将设置为 集合视图的宽度.)

During layout, only the size that corresponds to the appropriate scrolling direction is used. For example, for the vertical scrolling direction, the layout object uses the height value returned by your method. (In that instance, the width of the header would be set to the width of the collection view.)

但是,我需要将宽度设置为280,并且不能拉伸到集合视图的整个宽度.我该如何覆盖呢?

However, I need the width to be 280, and not stretch to the entire width of the collection view. How can I override this?

推荐答案

您无需在标题中添加子视图.

You don't need to add a subview to the header.

您希望在320的集合视图"中将标题宽度设置为280,因此在左侧和右侧分别应用内容插值" 20,如下所示:

You want a header width of 280 in a Collection View of 320, so apply a Content Inset of 20 on the left and right, like so:

快速

YourCollectionView.ContentInset = UIEdgeInsets(top: 0, left: 20, bottom: 20, right: 0)

Xamarin

YourCollectionView.ContentInset = new UIEdgeInsets(0, 20, 0, 20);

这篇关于UICollectionView标头宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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