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:@"[email protected]"]];

        [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];

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...