列表视图的背景图像仍然在单元格文本后面显示白色

发布于 2024-08-27 06:16:34 字数 245 浏览 5 评论 0原文

我想在列表视图后面放置部分可见的背景图像。我在笔尖中创建了一个列表视图,其后面有一个图像视图,并将列表视图背景设置为 20% 不透明度。这允许背景图像显示出来,但单元格中的文本在后面显示白色背景,如果我在 cellForRowAtIndexPath 中创建单元格,单元格也有白色背景。

我正在 cellForRowAtIndexPath 事件中创建和设置单元格文本标签和详细信息文本标签。

不知道如何摆脱它,或者是否有更好的方法来制作背景图像。

I wanted to put a background image partially visible behind a list view. I created a list view in my nib with an image view behind it and made the list view background 20% opacity. This allows the background image to show thru but my text in the cells show a white background behind and if I create the cells in cellForRowAtIndexPath the cells have a white background too.

I am creating and setting the cell textLabel and the detailTextLabel in the cellForRowAtIndexPath event.

Not sure how to get rid of that, or if there is a better way to do the background image.

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

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

发布评论

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

评论(1

江南月 2024-09-03 06:16:34

我遇到了类似的问题,并通过在 cellForRowAtIndexPath 中将 cell.contentView.backgroundColor 设置为 [UIColor clearColor] 来解决它。

如果您不想使整个单元格透明而仅使标签透明,则可以将 textLabel 和DetailTextLabel 的backgroundColor 属性也设置为清除:

cell.textLabel.backgroundColor = [UIColor clearColor];

要在运行时而不是在笔尖中设置表格的背景图像,您可以从图像创建新的 UIColor。就像这样:

UIImage *img = [UIImage imageWithContentsOfFile: someFilePath];  // get your background image
UIColor *backgroundColor = [[UIColor alloc] initWithPatternImage: img];
[myTable setBackgroundColor: backgroundColor]; 
[backgroundColor release];

I had a similar issue and resolved it by setting the cell.contentView.backgroundColor to [UIColor clearColor] in cellForRowAtIndexPath.

If you did not want to make the whole cell transparent but the labels only, you can set the backgroundColor attribute of the textLabel and detailTextLabel to clear as well:

cell.textLabel.backgroundColor = [UIColor clearColor];

To set the background image of a table at run time rather than in a nib you can create a new UIColor from an image. Like so:

UIImage *img = [UIImage imageWithContentsOfFile: someFilePath];  // get your background image
UIColor *backgroundColor = [[UIColor alloc] initWithPatternImage: img];
[myTable setBackgroundColor: backgroundColor]; 
[backgroundColor release];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文