gpt4 book ai didi

ios - 在 UICollectionView 单元格下添加 UILabel

转载 作者:可可西里 更新时间:2023-11-01 03:39:18 25 4
gpt4 key购买 nike

我有一个显示图像的 UICollectionView,类似于封面或 iBooks。我希望它在 UIImageView 下方显示音频剪辑的标题。我在我的 MainWindow.xib 中有一个 View Controller ,里面有一个 UICollectionView。我还为单元格本身构建了一个 NibCell.xib。在 Cell 中,我有一个 UIImageView,它填满了单元格底部 30 像素以外的所有区域。在这个区域我添加了一个 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 添加到单元格的内容 View

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

关于ios - 在 UICollectionView 单元格下添加 UILabel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20104840/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com