gpt4 book ai didi

ios - UITableViewCell imageView

转载 作者:行者123 更新时间:2023-11-28 22:23:23 25 4
gpt4 key购买 nike

我有样式为 UITableViewCellStyleSubtitle 的单元格。因此,如果对象是新的,我会添加图像,如果不删除该图像。我试试这个:

if (something) {
UIImage *img = [UIImage imageNamed:@"new.png"];
cell.imageView.image = img;;
}
else
{
cell.imageView.image = nil;
}

但是标题和副标题模式要靠左。如果不是新的,我希望会有空白。

我做这个:

if (something) {
UIImage *img = [UIImage imageNamed:@"new.png"];
cell.imageView.image = img;;
}
else
{
cell.imageView.image = nil;
CGSize itemSize = CGSizeMake(25, 38);
UIGraphicsBeginImageContext(itemSize);
CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
[cell.imageView.image drawInRect:imageRect];
cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}

25 和 38 它是我图片的宽度和高度。

它工作正常,也许这是实现此目标的更简单方法。

我想实现这个:


 --
| | TextLabel
-- detailtext label

--
| | TextLabel
-- detailtext label

--
| | TextLabel
-- detailtext label

TextLabel
detailtext label

所以单元格将是直的。如果不是新的,则没有图像,只有空间。如果是新图像。

最佳答案

尝试

 UIImage *img = [UIImage imageNamed:@"blankImage.png"];

的地方
cell.imageView.image = nil;

其中 blankImage.png 是简单的白色图像。

关于ios - UITableViewCell imageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19681727/

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