6

У меня есть UICollectionView, который показывает изображения, похожие на обложку или iBooks. Я хотел бы, чтобы он показывал название аудиоклипа под UIImageView. У меня в моем MainWindow.xib есть View Controller с UICollectionView внутри него. Я также создал NibCell.xib для самой ячейки. В ячейке у меня есть UIImageView, который заполняет все, кроме нижних 30 пикселей ячейки. В этой области я добавляю UILabel. Даю UIImageView тег 100 и UILabel тег 200, и в моем коде я поставил:Добавить UILabel под UICollectionView Cell

-(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 в contentview клетки

UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(0, 10, cell.bounds.size.width, 40)]; 
title.tag = 200; 
[cell.contentView addSubview:title]; 
Смежные вопросы