具有流布局的水平滚动方向模式下的UICollectionView标头位置 [英] UICollectionView header position in horizontal scroll direction mode with flow layout
本文介绍了具有流布局的水平滚动方向模式下的UICollectionView标头位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有带有水平滚动方向的Flow布局的ios UICollectionView. 在这种情况下,典型的标题位置在单元格的左侧.
I have ios UICollectionView with Flow layout with horizontal scroll direction. In this situation typical header position is on the left side of cells.
我要在单元格的顶部放置标题
I want to make header on the top of section cells
你知道我该怎么做吗?
推荐答案
我认为您可以使用标头的标准行为来获得所需的内容.
I think you can get what you need using standard behavior for the header.
进行设置(可能在viewDidLoad中):
Set it up (probably in 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;
}
这篇关于具有流布局的水平滚动方向模式下的UICollectionView标头位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文