将彩色UIImageView添加到UITableViewCell时的奇怪行为

哈西卜。萨马德

我通过以下方式将彩色状态指示器附加到每个UITableViewCell的左侧:

CGRect rect = CGRectMake(3, 1, 12, 42);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();

switch (cellState)
        {
            case State_OK:
                CGContextSetFillColorWithColor(context,
                                               [[UIColor customGreen] CGColor]);
                break;
            case State_Warning:
                CGContextSetFillColorWithColor(context,
                                               [[UIColor customYellow] CGColor]);
                break;
            case State_Critical:
                CGContextSetFillColorWithColor(context,
                                               [[UIColor customRed] CGColor]);
                break;
            case State_Unknown:
                CGContextSetFillColorWithColor(context,
                                               [[UIColor customGray] CGColor]);
                break;
        }

        CGContextFillRect(context, rect);
        UIImageView *imageView = [[UIImageView alloc] initWithImage:UIGraphicsGetImageFromCurrentImageContext()];
        imageView.alpha = 0.7;
        UIGraphicsEndImageContext();

        [cell.contentView addSubview:imageView];

return cell;

但是不知何故我得到了非常奇怪的颜色:

在此处输入图片说明

当我设置时imageView.alpha = 1;,颜色又好了:

在此处输入图片说明

像这样添加图像:

cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
cell.imageView.alpha = 0.7;

效果很好!即使有alpha但是我真的不想那样做。

安东尼奥·MG

问题可能在于颜色正在与单元格的背景混合。单元的背景颜色是什么?

另一个原因可能是您的单元格图像正在被重用,因此您将图像设置在先前图像的顶部。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

将阴影渐变添加到uitableviewcell / uiimageview的底部

PropertyGrid --> BindingList --> 将项目添加到列表时的奇怪行为

将发送特征添加到装箱的特征对象时出现奇怪的行为

尝试将文本添加到绘图时,哑铃图中的奇怪行为(变量重复)

将彩色椭圆添加到MenuItem

UISlider添加到UITableViewCell怪异的行为

添加到 $PATH 的奇怪行为 - ZSH

将全局变量添加到另一个文件中时的奇怪行为

将UIImageView添加到NSArray崩溃

将UILabel添加到UIImageView

删除行并将其添加到窗体时的奇怪行为

试图以编程方式将视图添加到 Kotlin 中的 ContraintLayout 的奇怪行为

将UIPanGesture添加到UITableViewCell

将UITextField添加到UITableViewCell

将子视图添加到UITableViewCell

将UIProgressBar添加到UITableViewCell

将进度视图添加到UITableViewCell

将选择点添加到彩色bspline

将彩色矩形添加到滴定图中

添加到Observable集合时的奇怪行为

奇怪的行为将此对象添加到此静态数组

奇怪的行为:将对象添加到ObservableCollection

将图像添加到UITableViewCell中的UIImageView会不希望地修改图像视图高度

为什么不能直接将UIView添加到UITableViewCell而将contentView添加到UITableViewCell

将项目添加到xml文件时出现奇怪的aapt.exe错误

尝试将元素添加到NSUserDefaults时出现App Delegate奇怪错误

循环时,图像未添加到UIImageView

如何将编译时元数据/行为添加到特定函数

将NaN添加到集合中时,导致行为不一致的原因