2

我有一个带有“更多”视图控制器的选项卡栏 (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;
}

在此先感谢,
朱利安

4

2 回答 2

1

做事moreController.topViewController.view有点危险。

我建议您将自己创建的选项卡放入带有普通图标的更多列表,然后通过普通导航控制器方法打开更多列表下的其他选项卡。当然,您需要从标签栏中删除所有溢出的标签项。

然而,可能有一种更优雅的方式来做到这一点。

于 2009-06-19T08:26:22.247 回答
1

首先,感谢您发布标签栏控制器的子类。我将它包含在我正在编写的应用程序中并遇到了同样的问题。

我的解决方案是简单地交换图像和突出显示的图像。为此,您必须更改 的方法tableView:cellForRowAtIndexPath:MoreTableViewDataSource.m例如:

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [dataSource tableView:tableView cellForRowAtIndexPath:indexPath];
    UIImageView *imageView = [cell imageView];
    UIImage *image = [imageView image];
    [imageView setImage:[imageView highlightedImage]];
    [imageView setHighlightedImage:image];
    return cell;
}

干杯,迈克尔

于 2009-12-30T18:46:56.503 回答