プログラムで imageView を一番上に追加しようとしていますがcollectionView
( 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
。どんな助けでも大歓迎です!
headerView
PS これはセクション ヘッダー タイトル ビュー用ではなく、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;
}