【发布时间】:2015-06-01 18:22:15
【问题描述】:
我有一个带有以下相关方法的collectionView:
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView
viewForSupplementaryElementOfKind:(NSString *)kind
atIndexPath:(NSIndexPath *)indexPath {
if (kind == UICollectionElementKindSectionHeader) {
Scoreboard *thisScoreboard = [self.scoreboards objectAtIndex:indexPath.section];
ScoreboardReusableView *view = nil;
view = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader
withReuseIdentifier:@"scoreboardHeader"
forIndexPath:indexPath];
//view.backgroundColor = [UIColor yellowColor];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 20)];
//label.text = [NSString stringWithFormat:@"%@ vs %@", thisScoreboard.awayteam, thisScoreboard.hometeam];
label.text = [NSString stringWithFormat:@"%ld", (long)indexPath.section];
[view addSubview:label];
return view;
}
return nil;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
{
return CGSizeMake(self.view.frame.size.width, 34);
}
但是,标签文本是重叠的。这是collectionView的两个截图。第 0 节和第 1 节(注意文本不重叠):
第 2 节和第 3 节(文本在此处和所有后续节标题上重叠):
我的标题 xib ScoreboardReusableView 完全空白,因为无论我在其中放入什么(例如,UILabel 或 UIImageView,它都不会显示在 UICollectionView 标题中)。最好我会在 xib 中设计标题,但由于这不起作用,我尝试以编程方式进行,但现在标签重叠。
【问题讨论】:
标签: ios objective-c uicollectionview uicollectionviewcell uicollectionviewlayout