【发布时间】:2015-01-05 12:19:06
【问题描述】:
UITableView 也有类似的功能。我可以为UITableView 或UITableView 中的每个部分添加一个标题。这里的问题是如何以编程方式将标题添加到UICollectionView?不是UICollectionView的每个部分。
【问题讨论】:
标签: ios storyboard uicollectionview
UITableView 也有类似的功能。我可以为UITableView 或UITableView 中的每个部分添加一个标题。这里的问题是如何以编程方式将标题添加到UICollectionView?不是UICollectionView的每个部分。
【问题讨论】:
标签: ios storyboard uicollectionview
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
if (kind == UICollectionElementKindSectionHeader) {
UICollectionReusableView *reusableview = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView" forIndexPath:indexPath];
if (reusableview==nil) {
reusableview=[[UICollectionReusableView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
}
UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
label.text=[NSString stringWithFormat:@"Recipe Group #%li", indexPath.section + 1];
[reusableview addSubview:label];
return reusableview;
}
return nil;
}
【讨论】: