我通过以下方式将彩色状态指示器附加到每个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
。但是我真的不想那样做。
问题可能在于颜色正在与单元格的背景混合。单元的背景颜色是什么?
另一个原因可能是您的单元格图像正在被重用,因此您将图像设置在先前图像的顶部。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句