【问题标题】:How to set tint color according to TabBar selected index?如何根据 TabBar 选择的索引设置色调颜色?
【发布时间】:2023-04-05 03:41:01
【问题描述】:

我想根据标签栏的选定索引更改 tintColor 属性。我现在使用的代码不起作用,所有的标签栏视图都有这个代码:

- (void)viewDidAppear:(BOOL)animated{

    switch (self.tabBarController.selectedIndex) {
        case 0:
            self.tabBarController.tintColor = [UIColor colorWithRed:147/255 green:22/255 blue:0/255 alpha:1.0];
            break;

        case 1:
            self.tabBarController.tintColor = [UIColor whiteColor];
            break;

        case 2:
            self.tabBarController.tintColor = [UIColor greenColor];
            break;

        default:
            break;
    }
}

【问题讨论】:

    标签: ios tabbar


    【解决方案1】:

    你不需要这样做;相反,将其放在包含的控制器的 viewWillAppear: 方法中:

    控制器 1:

    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
        self.tabBarController.tabBar.tintColor = [UIColor blueColor];
    }
    

    控制器 2:

    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
        self.tabBarController.tabBar.tintColor = [UIColor yellowColor];
    }
    

    这假设 iOS5+。希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2023-03-31
      • 2011-02-19
      • 2011-01-20
      • 1970-01-01
      • 1970-01-01
      • 2021-11-29
      • 2018-12-07
      • 2023-01-12
      • 1970-01-01
      相关资源
      最近更新 更多