UIColor colorWithPatternImage:UITableView的separatorColor中的透明度问题

11

我在设置我的有图案的 UIColor 时遇到了问题。在 iOS 5 中一切正常,但在 iOS 4.3 中出现了问题。我添加了一张图片以更好地理解。我已经在谷歌上搜索了一些内容,并发现答案可能是将 opaque 属性设置为 NO。但我已经将每个 viewcontentViewbackgroundViewtableViewCellopaque 值设置为 NO

You can see that the separator color is black, where the image has of the pattern has transparency

您可以看到分隔符颜色是黑色,当图案具有透明度时,它的图像中会出现该模式


同样的问题,你解决了吗? - Lytol
还没有。移除分隔符并将一个UIView设置为不透明的分隔符,使用正确的背景颜色,这样做是有效的。 - Dries De Smet
2个回答

18

这似乎是 iOS 4.3 中的一个 bug,在 5.0 中已经修复。

为了使其在 4.3 上运行,您需要在将视图的 backgroundColor 设置为模式图像后,将视图和层都设置为非不透明,如下所示:

UIImage* pattern = [UIImage imageNamed:@"translucentPatternImage.png"];
view.backgroundColor = [UIColor colorWithPatternImage:pattern];
[view.layer setOpaque:NO];
view.opaque = NO;

1
确保在设置背景色之后将图层设置为非不透明以使此功能生效。 - Dunkelstern

0
如果我没记错的话,你需要设置 TableViewCell 中标签的背景颜色。类似这样的代码:
[cell.textLabel setBackgroundColor:[UIColor clearColor]];

不是灰色框框困扰我,我已经设置它们来掩盖内容 ;) - Dries De Smet
抱歉,哈哈。您是想要移除分隔符的颜色吗? - Scott Sherwood
正如您在顶部所看到的,左右10个像素的分隔符颜色是透明的。在另外两个分隔符上,这种透明度变成了黑色。这在iOS 5上我没有遇到过,只有在iOS 4上出现。 - Dries De Smet

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接