如何设置moreNavigationController表的选择颜色?

时间:2013-10-22 20:24:47

标签: ios ios6 uitabbarcontroller

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

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

enter image description here

此问题特定于iOS 6,因为在iOS 7上使用了灰色选择颜色。

1 个答案:

答案 0 :(得分: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;
}
相关问题