在UICollectionView Cell下添加UILabel

use*_*452 6 uiimageview uilabel ios uicollectionview uicollectionviewcell

我有一个显示图像的UICollectionView,类似于封面艺术或iBooks.我希望它能在UIImageView下面显示音频剪辑的标题.我在我的MainWindow.xib中有一个视图控制器,里面有一个UICollectionView.我还为单元格本身构建了一个NibCell.xib.在Cell中,我有一个UIImageView,它可以填充除了底部30 px的所有细胞.在这个区域我添加了一个UILabel.我给UIImageView标签100和UILabel标签200,在我的代码中我把:

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

     RSSEntry *entry = [_allEntries objectAtIndex:indexPath.row];

    static NSString *cellIdentifier = @"cvCell";

    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];

    UIImageView *titleLabel = (UIImageView *)[cell viewWithTag:100];
     UILabel *titleLabel2 = (UILabel *)[cell viewWithTag:200];

           NSString *thearticleImage = entry.articleImage;
               [titleLabel setImageWithURL:[NSURL URLWithString:entry.articleImage] placeholderImage:[UIImage imageNamed:@"icon@2x.png"]];

        [titleLabel2 setText:entry.articleTitle];
        return cell;
}
Run Code Online (Sandbox Code Playgroud)

但是,无论在NibCell.xib中如何设置单元格,都会使UIImageView填充整个单元格,并在其上添加UILabel.有什么建议?

sno*_*s74 12

您需要将UILabel添加到单元格的内容视图中

UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, cell.bounds.size.width, 40)];
title.tag = 200;
[cell.contentView addSubview:title];
Run Code Online (Sandbox Code Playgroud)