【发布时间】:2014-07-26 01:44:20
【问题描述】:
我有一个 UICollectionView 显示图像的水平布局。在每张图片下,我都显示了一个标签。在情节提要中,我扩展了单元格的高度,以便标签显示在单元格下方。我还将情节提要中 UIImageView 的高度设置为比单元格低 20pts。但是,无论我做什么,图像都会占据整个单元格,并且标签会显示在图像顶部。我应该在其他地方设置图像视图的大小吗?我发现了这个thread,我认为它会有所帮助,因为它基本上是相同的,但解决方案对我没有帮助。
这是我的代码...
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell"; // string value identifier for cell reuse
ImageViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
cell.layer.borderWidth = 1.0;
cell.layer.borderColor = [UIColor grayColor].CGColor;
NSString *myPatternString = [self.imageNames objectAtIndex:indexPath.row];
cell.imageView.image = [self.imagesArray objectAtIndex:indexPath.row];
cell.imageView.contentMode = UIViewContentModeScaleAspectFill;
cell.imageView.clipsToBounds = YES;
CGSize labelSize = CGSizeMake(CellWidth, 20);
UILabel *testLabel = [[UILabel alloc] initWithFrame:CGRectMake(cell.bounds.size.width/2, cell.bounds.size.height-labelSize.height, cell.bounds.size.width, labelSize.height)];
testLabel.text = myPatternString;
[cell.contentView addSubview:testLabel];
return cell;
}
【问题讨论】:
标签: uiimageview uicollectionview