ios – 具有流布局的水平滚动方向模式中的UICollectionView标题位置
2019年08月04日
作者:佚名
我有ios UICollectionView与Flow布局水平滚动方向.
在这种情况下,典型的标题位置在单元格的左侧.
在这种情况下,典型的标题位置在单元格的左侧.
我想使标题在单元格的顶部
你有什么想法我该怎么做?
解决方法
我认为您可以使用标题的标准行为来获得所需的内容.
设置(可能在viewDidLoad中):
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; flowLayout.headerReferenceSize = CGSizeMake(self.collectionView.bounds.size.width,30); // other setup [self.collectionView setCollectionViewLayout:flowLayout];
然后回答标题视图:
#define MY_HEADER_LABEL_TAG 128 - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath { UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind: UICollectionElementKindSectionHeader withReuseIdentifier:@"SectionHeader" forIndexPath:indexPath]; UILabel *label = (UILabel *)[headerView viewWithTag:MY_HEADER_LABEL_TAG]; if (!label) { label = [[UILabel alloc] initWithFrame:CGRectInset(headerView.bounds,5,5)]; label.tag = MY_HEADER_LABEL_TAG; label.font = [UIFont boldSystemFontOfSize:12]; label.textColor = [UIColor darkGrayColor]; [headerView addSubview:label]; } label.text = [NSString stringWithFormat:@"Section %d",indexPath.section]; return headerView; }
以上是来客网为你收集整理的ios – 具有流布局的水平滚动方向模式中的UICollectionView标题位置全部内容,希望文章能够帮你解决ios – 具有流布局的水平滚动方向模式中的UICollectionView标题位置所遇到的程序开发问题。
如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。