ios – 在UICollectionView Cell下添加UILabel

我有一个显示图像的UICollectionView,类似于封面艺术或iBooks.我希望它能在UI ImageView下面显示音频剪辑的标题.我在我的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;
}

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

解决方法

您需要将UILabel添加到单元格的内容视图中
UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(0,10,cell.bounds.size.width,40)];
title.tag = 200;
[cell.contentView addSubview:title];

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...