我無法通過按下uibutton更新uibartint顏色,它不起作用。這是我的層次結構:我如何實時更新UITabBarController外觀?
AppDelegate->HomeViewController (that holds my tabBarController)->ChildViewController
我想通過按下ChildViewController中的按鈕來實時更改UiTabbarController顏色。這是我使用的代碼:
UIColor* blu = [UIColor colorWithRed: 0.0/255 green: 161.0/255 blue: 223.0/255 alpha: 1];
[[UIView appearance] setTintColor:blu];
[[UITabBar appearance] setTintColor:blu];
[[UISlider appearance] setTintColor:blu];
[[UINavigationBar appearance] setTintColor:blu];
它不會改變我的TabBar的顏色實時,它改變只有當我使用TabBar的初始化過程中使用它的顏色。我已經搜索並嘗試不同的解決方案:
[self.tabBarController.tabBar setHidden:YES];
[self.tabBarController.tabBar setHidden:NO];
在我的情況不工作
CALayer *layer2 = self.tabBarController.view.layer;
[layer2 setNeedsDisplay];
[layer2 displayIfNeeded];
沒有我的情況下
setNeedsStatusBarAppearanceUpdate
工作在我的情況下不能正常工作。
我也嘗試在appDelegate中創建一個方法來包含所有這些嘗試,我必須從ChildViewController嘗試此方法,而不是直接調用代碼。結果是一樣的。 如何才能刷新uitabbar並按下按鈕更改顏色?
它的工作原理,但以這種方式: [self.tabBarController.tabBar setTintColor:blu]; – user31929