6

我有一个显示图像的UICollectionView,类似于封面艺术或iBooks。我想让它显示UIImageView下面的音频剪辑的标题。我在我的MainWindow.xib里面有一个带有UICollectionView的View Controller。我还为单元本身构建了一个NibCell.xib。在单元格中,我有一个UIImageView,填满了单元格的底部30像素。在这个区域我添加一个UILabel。我给的UIImageView的100标签和的UILabel的200标签,在我的代码,我把:在UICollectionView单元格中添加UILabel单元格

-(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。有什么建议么?

回答

12

您需要将您的UILabel添加到单元格的内容查看

UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, cell.bounds.size.width, 40)]; 
title.tag = 200; 
[cell.contentView addSubview:title]; 
相关问题