タブバーの設定メニューのナビゲーションバーの色を設定する方法
-
05-07-2019 - |
質問
死んだImageShackリンクを削除
変更する必要があるビューを見るとわかるように、タブバーの順序をカスタマイズするために提供されているビューです。 Navigation Barの色を変更したい(「Configure」を意味する「Konfigurieren」を表示する)誰でも私を助けることができますか?
解決
int AppDelegateを使用
tabBarController.moreNavigationController.navigationBar.tintColor = [UIColor blackColor];
他のヒント
あなたが探しているのはこれだと思います(通常はアプリデリゲートでNavigation Controllerを作成するときに行います):
UINavigationController *navigationController;
...
navigationController.navigationBar.tintColor = [UIColor blackColor];
間違いなく動作します! :-)
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
簡単にすることができます(タブバーデリゲートで使用):
- (void)tabBarController:(UITabBarController *)tabBarController willBeginCustomizingViewControllers:(NSArray *)viewControllers {
id modalViewCtrl = [[[tabBarController view] subviews] objectAtIndex:1];
if([modalViewCtrl isKindOfClass:NSClassFromString(@"UITabBarCustomizeView")] == YES)
((UINavigationBar*)[[modalViewCtrl subviews] objectAtIndex:0]).tintColor = [UIColor redColor];
}
それぞれを個別に変更する代わりに、すべてのナビゲーションバーのスタイルを変更する簡単な方法があります。
[[UINavigationBar appearance] setBarStyle:UIBarStyleBlack];
最初のビューの1つでこのコードを設定するだけです。これにより、より多くのNavigation Controllerと設定Navigation Controller(「Navigation Navigation Controller」の「Edit」をクリックすると表示されます)は異なるスタイルになります。
このように、色を別の色に変更したり、背景画像を変更したりできます。
これがお役に立てば幸いです。
次のようにConfigure NavBarの色を変更できました:
- UITabBarControllerを継承する新しいクラスを作成します。
-
このメソッドを実装します:
-(void)beginCustomizingTabBar:(id)sender { [super beginCustomizingTabBar:sender]; // Get the new view inserted by the method called above id modalViewCtrl = [[[self view] subviews] objectAtIndex:1]; if([modalViewCtrl isKindOfClass:NSClassFromString(@"UITabBarCustomizeView")] == YES) { UINavigationBar* navBar = [[modalViewCtrl subviews] objectAtIndex:0]; [navBar setBarStyle:UIBarStyleBlackTranslucent]; [navBar setTranslucent:YES]; } }
user486217によって与えられた答えに基づいて、これはさらに防御的にコーディングされる可能性があります:
id modalViewCtrl = [controller.view.subviews objectAtIndex:1]; if([modalViewCtrl isKindOfClass:NSClassFromStrin(@"UITabBarCustomizeView")] == YES) { id navigationBar = [[modalViewCtrl subviews] objectAtIndex:0]; if ([navigationBar isKindOfClass:[UINavigationBar class]]) { ((UINavigationBar*)navigationBar).tintColor = [UIColor redColor]; } }}
標準色(グレー、黒、白)を探している場合は、xCode 5内でこれらの値を設定できます。ViewController全体を選択し、属性インスペクターを選択します。属性の下にある[トップバー]の横にドロップダウンがあります。そこで、Navigation Bar Controllerの色と不透明度のさまざまな設定を選択できます。
以下に、いくつかのスクリーンショットを示します。これがお役に立てば幸いです!