将XIB粘贴到导航栏ios

时间:2017-05-25 14:07:02

标签: ios objective-c

我有xib,我注册了它:

[self.collectionView registerNib:[UINib nibWithNibName:@"MyCollectionView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"MyCollectionView"];

我希望将它粘贴到导航栏 - 每次都必须在导航栏下(例如,当我滚动页面时)。如何将其固定(导航)到导航栏?

1 个答案:

答案 0 :(得分:1)

在您的流布局文件初始化中,您可以使用:

self.sectionHeadersPinToVisibleBounds = true

如果您在viewDidLoad使用

中没有自定义布局文件
let layout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout // casting is required as its feature of UICollectionViewFlowLayout
layout?.sectionHeadersPinToVisibleBounds = true

目标C版

UICollectionViewFlowLayout *layout = (UICollectionViewFlowLayout*) collection.collectionViewLayout;
layout.sectionHeadersPinToVisibleBounds = YES;