我正在尝试以collectionView
编程方式将 imageView 添加到我的顶部(类似于 a tableViewHeaderView
),但到目前为止,我正在尝试的viewDidLoad
内容并不完全有效。
UIImageView *headerImageView = [[UIImageView alloc] init];
if ([isHeaderVisible intValue]== YES) {
NSLog(@"Header View was found.");
[headerImageView setImage:[UIImage imageNamed:headerImage]];
[headerImageView setUserInteractionEnabled:YES];
[headerImageView setFrame:CGRectMake(0, 0, 320, 160)];
[headerImageView setContentMode:UIViewContentModeScaleAspectFit];
}
else {
NSLog(@"No Header view found.");
[headerImageView setImage:nil];
[headerImageView setFrame:CGRectMake(0, 0, 0, 0)];
}
是否找到标题视图的逻辑正在运行,但我无法UIImageView
正常工作。任何帮助将不胜感激!
PS 这不是用于 Section Header Title View,它类似于headerView
在 Apple 的 App Store 中找到的。
更新:
我还在我的viewController
. 所以基本上我想使用节标题和视图标题。我如何能够使用以下内容创建节标题和视图标题:
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
UICollectionReusableView *reusableview = nil;
if (kind == UICollectionElementKindSectionHeader) {
DetailCollectionHeaderView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView" forIndexPath:indexPath];
headerView.sectionTitle.text = collectionSectionTitle;
headerView.backgroundImage.image = [UIImage imageNamed:@"WFSectionHeader.png"];
reusableview = headerView;
}
if (kind == UICollectionElementKindSectionFooter) {
UICollectionReusableView *footerview = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"FooterView" forIndexPath:indexPath];
reusableview = footerview;
}
return reusableview;
}