简体   繁体   English

如何将表格视图的背景(窗口)设置为图像?

[英]How do I set the background (window) for a tableview to an image?

I have set the background colour of my UITableView to clear so that I can see the UIWindow. 我将UITableView的背景色设置为清除,以便可以看到UIWindow。 But I want to change the image presented (from background.png), depending on my selection. 但是我要更改显示的图像(来自background.png),具体取决于我的选择。 An example would be: If (selection = 'blue') then image = bluesky.png if (selection = 'green') then image = 'greengrass.png 一个例子是:如果(selection ='blue')则image = bluesky.png如果(selection ='green')则image ='greengrass.png

thx, wes 谢谢

您可以使用图像设置表格视图的背景颜色,而不是使背景清晰并在其后放置图像。

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

Just change the background image based on the selection, assuming your controller is UITableViewController or implements the UITableViewDelegate protocol, do something like: 只需根据选择更改背景图像,并假设您的控制器是UITableViewController或实现了UITableViewDelegate协议,请执行以下操作:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
     NSString *imageName = @"default.png";
     switch (indexPath.row) {
       case ...: // fill correct imageName based on selection
     }

     self.myBackgroundImageView.image = [UIImage imageNamed:imageName];
}

Btw - this also assumes you have an IBOutlet or something for your background image. 顺便说一句-这也假设您有IBOutlet或背景图片。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM