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.
精彩评论