1

如何为 iOS 6 上的更多选项卡视图控制器中列出的视图控制器设置单元格选择颜色?

默认值为蓝色,对于使用非默认颜色的应用来说,这看起来很糟糕。如果可能的话,我想将其设置为自定义颜色,但将其设置为灰色即可。

在此处输入图像描述

这个问题是 iOS 6 特有的,因为在 iOS 7 上使用了灰色的选择颜色。

4

1 回答 1

3

我们可以通过为 MoreNavigationController 创建自定义数据源来更新选项卡视图控制器的更多中列出的视图控制器的单元格选择颜色。

我创建了一个可能有帮助的示例项目 - https://github.com/deepthit/CustomizeMoreNavigationController.git

在自定义数据源对象中,我们可以重写 cellForRowAtIndexPath 方法来为单元格设置 selectedbackgroundView。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  UITableViewCell *cell = [originalDataSource tableView:tableView cellForRowAtIndexPath:indexPath];

  // Set background color
  UIView *background = [[UIView alloc] initWithFrame:cell.frame];
  background.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  background.backgroundColor  = [UIColor whiteColor];
  cell.backgroundView = background;

  // Set selected background color
  UIView *selectionColor = [[UIView alloc] initWithFrame:cell.frame];
  selectionColor.backgroundColor = [UIColor greenColor];
  selectionColor.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  cell.selectedBackgroundView = selectionColor;

  return cell;
}
于 2013-10-22T21:52:09.000 回答