【问题标题】:How do I set the background (window) for a tableview to an image?如何将表格视图的背景(窗口)设置为图像?
【发布时间】:2010-08-04 00:38:03
【问题描述】:

我已将 UITableView 的背景颜色设置为清除,以便我可以看到 UIWindow。但我想根据我的选择更改呈现的图像(来自 background.png)。一个例子是: 如果(选择='蓝色')然后图像= bluesky.png if (selection = 'green') then image = 'greengrass.png

谢谢, 韦斯

【问题讨论】:

    标签: iphone uitableview uiimage


    【解决方案1】:

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

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

    【讨论】:

    • 我最终得到的工作方式是独立于 UITableView 设置委托窗口背景
    【解决方案2】:

    只需根据选择更改背景图像,假设您的控制器是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 或其他东西作为您的背景图片。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-25
      • 2013-10-28
      • 2014-05-08
      • 2013-11-26
      • 1970-01-01
      • 2011-01-11
      相关资源
      最近更新 更多