UITableView 背景图像 Alpha 问题

发布于 2024-07-13 06:09:05 字数 424 浏览 8 评论 0原文

我有一个 UIView 和一个 UITableView 作为子视图。 UIView 通过 setBackGroundColor 将图像应用到其背景,并且我以相同的方式将背景应用到 UITableView。 两个图像都是 PNG,并且 UITableView 的背景具有似乎不起作用的透明度级别 - PNG 似乎在不考虑其中的透明度数据的情况下进行渲染 - 我应该看到背景通过它的UIView。 我用于应用背景图像的基本代码是:

UIImage *patternImage = [UIImage imageNamed:@"background.png"];
[tableContainer setBackgroundColor:[UIColor colorWithPatternImage: patternImage]];

我被难住了。 有任何想法吗?

I have a UIView with a UITableView for a subview. The UIView has an image applied to its background via setBackGroundColor, and I have applied a background to the UITableView in the same manner. Both images are PNGs, and the the background for the UITableView has levels of transparency in it that don't appear to be working -- the PNG seems to be rendered without regard to the transparency data within it -- I should be seeing the background of the UIView through it. The basic code I am using for applying the background images is:

UIImage *patternImage = [UIImage imageNamed:@"background.png"];
[tableContainer setBackgroundColor:[UIColor colorWithPatternImage: patternImage]];

I'm stumped. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

段念尘 2024-07-20 06:09:05

您需要确保您的表视图不是不透明的。

在 Interface Builder 中,取消选中表格视图的“不透明”设置。 或者,在代码中,

tableView.opaque = NO;

请记住,表视图的任何类型的透明度都会显着降低性能。 如果您只有几行,可能没问题,但如果您进行任何滚动,请做好承受一些痛苦的准备。 确保在发布之前在真实设备上进行测试。

You need to make sure your table view is not opaque.

In Interface Builder, uncheck your table view's 'Opaque' setting. Or, in code,

tableView.opaque = NO;

Keep in mind that any sort of transparency in regard to table views will slow performance dramatically. If you only have a few rows, you'll probably be OK, but if you do any scrolling, be prepared for some pain. Make sure you test on a real device before release.

皇甫轩 2024-07-20 06:09:05

事实证明,我需要设置单元格 contentView 的背景颜色,而不是设置单元格本身的背景颜色。

再次感谢您的帮助!

Turns out that I needed to set the backgroundColor of the cell's contentView rather than setting the backgroundColor of the cell itself.

Thanks again for the help!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文