开发者

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

开发者 https://www.devze.com 2023-01-10 06:51 出处:网络
I have set the background colour of my UITableView to clear so that I can see the UIWindow.But I want to change the image presented (from background.png), depending on my selection.An example would be

I have set the background colour of my UITableView to clear so that I can see the UIWindow. But I want to change the image presented (from background.png), depending on my selection. An example would be: If (selection = 'blue') then image = bluesky.png if (selection = 'green') then image = 'greengrass.pn开发者_StackOverflowg

thx, wes


Instead of making the background clear and putting an image behind it, you can set the tableview's background color using an image

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:

- (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.

0

精彩评论

暂无评论...
验证码 换一张
取 消