gpt4 book ai didi

iPhone:分组TableView背景图像问题

转载 作者:行者123 更新时间:2023-12-03 19:31:36 26 4
gpt4 key购买 nike

大家好,这看起来应该是一个简单的问题;我真的希望是这样。一如既往,提前致谢!

我想做的就是将背景图像添加到分组样式表格 View 中。我在 viewDidLoad 中使用以下方法:

self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]];

不幸的是,background.png似乎不仅绘制在单元格后面,而且还绘制在单元格和标题的背景上,如下所示:

alt text http://www.freeimagehosting.net/uploads/194449ffc1.png

我知道该网站上有一些解决类似问题的问题,但恐怕我无法完成任何工作。 How can I set the background of UITableView (the tableview style is "Grouped") to use an image?让我添加

self.tableView.opaque = NO;
self.tableView.backgroundView = nil;

到viewDidLoad并添加

cell.backgroundView = nil;
cell.opaque = NO;

配置我的单元格。不用说,它不起作用。添加

cell.backgroundColor = [UIColor clearColor];

也没有用。可悲的是,这是我最后的想法。如果可能的话,我真的希望能够在不添加界面生成器背景的情况下做到这一点。我更喜欢以编程方式尽可能多地完成任务。我希望这个问题不会太贪心。再次感谢!

***编辑:***

我遇到了另一种方法来完成此任务,但遇到了另一个问题。我在 viewDidLoad 中添加了以下代码:

    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
bgView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]];
[self.tableView.window addSubview:bgView];

[self.tableView addSubview:bgView];
[self.tableView sendSubviewToBack:bgView];

它看起来很有希望,而且很可能是这样,但不幸的是它给了我以下内容: alt text http://www.freeimagehosting.net/uploads/c02dd68e20.png

看起来好像它没有被发送到后面并且标题以某种方式显示出来,或者单元格随之到了后面。我一点也不确定。如有任何建议,我们也将不胜感激。

在这里我找到了编辑代码: Add UIView behind UITableView in UITableViewController code

最佳答案

我经历了与你在这里描述的类似的路径。我终于在以下帖子中找到了对我有用的答案:

How to set the background of a UITableView to an image?

这是用户 rkb 发布的两行代码。代码如下:

self.tableView.backgroundColor = [UIColor clearColor];

self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithData:imageData]];

关于iPhone:分组TableView背景图像问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3384715/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com