【问题标题】:UITabBarController moreNavigationController table cell background imagesUITabBarController moreNavigationController 表格单元格背景图片
【发布时间】:2009-10-12 19:28:26
【问题描述】:

哇,那是一口。 :)

我们已经在customizing the more menu (table view) in a tab bar 上看到了一个不错的帖子。

对于我们的下一个技巧......如何将背景图像添加到表格单元格?

我认为我可以在我的 More Table View 的数据源类中重写 tableView:cellForRowAtIndexPath: (方法见前面的链接)。唉,它只会改变每个单元格左右的图像和附件视图下的背景。

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    // Let the original Data Source get a hold of the cell first.
    UITableViewCell *cell = [originalDataSource tableView:tableView cellForRowAtIndexPath:indexPath];

    // If we override the textColor, that works fine. (Commented out for now.)
    //cell.textLabel.textColor = [UIColor whiteColor];

    // If we override the background view … that doesn't work so well.
    cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellBackground.png"]];

    return cell;
}

我知道,imageNamed: 是邪恶的,也许我应该创建一个背景图像并在整个过程中重复使用它(而不是分配多个 UIImageView 对象)。除了这些东西,还有什么想法吗? (我也尝试调整 textLabel 的 backgroundColor,但无济于事……除非我在那里做错了。)

【问题讨论】:

标签: iphone uitableview uitabbarcontroller background-image


【解决方案1】:

Here 是答案...

中添加代码
  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

MoreTableViewDataSource的方法

【讨论】:

    【解决方案2】:

    除了 Sijo 的回答帖子(谢谢!)之外,我刚刚意识到有 another thread on SO 采取了类似的策略......除了我对这段代码了解更多。但是,我从来没有将它交叉引用回这个问题/线程!所以就在这里。具体见 Ian1971 的回复。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-28
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-16
      • 1970-01-01
      相关资源
      最近更新 更多