我有一个带有“更多”视图控制器的选项卡栏 (UITabBarController) 应用程序,因为它有 5 个以上的视图。我的应用程序的其余部分具有黑色背景和白色文本,我已经能够自定义此表以匹配它。然而,因此,通常出现在“更多”表左侧的选项卡栏图像是不可见的(因为它们适用于白色背景)。我需要找到一种方法来使标签栏图像显示为它们在标签栏中的显示方式,该标签栏本身具有黑色背景。
例子:
我将 TabBarController 子类化并更改了“MoreTableView”的数据源:
TabBarController.m
- (void)viewDidLoad {
[super viewDidLoad];
UINavigationController *moreController = self.moreNavigationController;
moreController.navigationBar.barStyle = UIBarStyleBlackOpaque;
if ([moreController.topViewController.view isKindOfClass:[UITableView class]])
{
UITableView *view = (UITableView *)moreController.topViewController.view;
view.separatorColor = [[UIColor alloc] initWithRed:0.3 green:0.3 blue:0.3 alpha:1.0];
view.backgroundColor = [UIColor blackColor];
view.dataSource = [[MoreTableViewDataSource alloc] initWithDataSource:view.dataSource];
}
}
MoreTableViewDataSource.m
-(MoreTableViewDataSource *) initWithDataSource:(id<UITableViewDataSource>) dataSource
{
originalDataSource = dataSource;
[super init];
return self;
}
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
{
return [originalDataSource tableView:table numberOfRowsInSection:section];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [originalDataSource tableView:tableView cellForRowAtIndexPath:indexPath];
cell.textColor = [[UIColor alloc] initWithRed:1 green:0.55 blue:0 alpha:1.0];
cell.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"customAccessory.png"]];
return cell;
}
在此先感谢,
朱利安