[英]How do I set the background (window) for a tableview to an image?
我將UITableView的背景色設置為清除,以便可以看到UIWindow。 但是我要更改顯示的圖像(來自background.png),具體取決於我的選擇。 一個例子是:如果(selection ='blue')則image = bluesky.png如果(selection ='green')則image ='greengrass.png
謝謝
您可以使用圖像設置表格視圖的背景顏色,而不是使背景清晰並在其后放置圖像。
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"greengrass.png"]];
只需根據選擇更改背景圖像,並假設您的控制器是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];
}
順便說一句-這也假設您有IBOutlet或背景圖片。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.