更改moreNavigationController中UIImageView的TintColor

3

我有这段代码来定制我的moreNavigationController:

UITableView *tView = (UITableView*)tabController.moreNavigationController.topViewController.view;
if ([[tView subviews] count]) {
    for (UITableViewCell *cCell in [tView visibleCells]) {
        cCell.textLabel.textColor = TABLECELL_TEXT_COLOR;
        cCell.textLabel.highlightedTextColor = TABLECELL_TEXT_COLOR_HIGHLIGHTED;
        cCell.contentView.backgroundColor = TABLECELL_BACKGROUND_COLOR;
        cCell.backgroundColor = TABLECELL_BACKGROUND_COLOR;
        UIView * selectedBackgroundView = [[UIView alloc] init];
        UIColor *uicCell = TABLECELL_BACKGROUND_COLOR_SELECTED
        [selectedBackgroundView setBackgroundColor:uicCell];
        [cCell setSelectedBackgroundView:selectedBackgroundView];
    }
}

我将我的TabBar图像更改为灰色和绿色,但当我点击“更多”按钮时,结果是这样的: enter image description here 我不明白为什么是蓝色的,所以我尝试更改色调颜色,但似乎没有任何作用。
我已将以下代码添加到我的函数中:
UIImageView *imgV = cCell.imageView;
imgV.tintColor = [UIColor redColor];
[imgV setTintColor:[UIColor redColor]];
UIImageView *imgV2 = imgV;

以下是您需要翻译的结果:

我能在变量中看到这些内容:

enter image description here

enter image description here

非常感谢任何帮助。


1
尝试一下 --- image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; - Awesome.Apple
将那段代码放在 viewDidLayoutSubviews 中。 - techloverr
感谢大家,我已经尝试了单独和一起两种方法,但图像仍然是蓝色而不是红色。 - Stornu2
1
尝试设置单元格的tintColor。 - techloverr
我已经尝试了cCell.tintColor和cCell.contentView.tintColor,结果是一样的,我开始感到沮丧。 - Stornu2
2个回答

4

试了很多次后,这是最终的代码:

UITableView *tView = (UITableView*)tabController.moreNavigationController.topViewController.view;
UIColor *tViewColor = MORE_TINTCOLOR;
[tView setTintColor: tViewColor];
if ([[tView subviews] count]) {
    for (UITableViewCell *cCell in [tView visibleCells]) {
        cCell.textLabel.textColor = TABLECELL_TEXT_COLOR;
        cCell.textLabel.highlightedTextColor = TABLECELL_TEXT_COLOR_HIGHLIGHTED;
        cCell.contentView.backgroundColor = TABLECELL_BACKGROUND_COLOR;
        cCell.backgroundColor = TABLECELL_BACKGROUND_COLOR;
        UIView * selectedBackgroundView = [[UIView alloc] init];
        UIColor *uicCell = TABLECELL_BACKGROUND_COLOR_SELECTED
        [selectedBackgroundView setBackgroundColor:uicCell];
        [cCell setSelectedBackgroundView:selectedBackgroundView];
    }
}

你需要改变UITableView的TintColor。
谢谢大家。

1
这是针对 Swift 5 的解决方案:
UITabBarController 的子类的 viewDidLoad 中添加以下内容。
if let topViewController = self.moreNavigationController.topViewController {
    if let tableView = topViewController.view as? UITableView {
        tableView.tintColor = .accent
    }
}

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接