1

我知道這個主題已經有一些線程,但它們只部分解決了我的問題。 我設法定製moreNavigationController的導航欄的顏色和標籤顏色在​​這裏看到: picture1在iOS 7中自定義moreNavigationController

但我通過自定義,如果你的「編輯」,點擊右側足見其觀點得到了一些問題。這是它現在的樣子: picture2

我想實現什麼?在白色

  • 顏色

    • 顏色做了的導航欄紅色
    • 顏色爲紅色

    我已經通過

    UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController; 
    
    得我在我的AppDelegate的UITabBarController參考圖標色彩

    而且我還設置了此tabBarController的委託和委託方法- (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]).barTintColor = [UIColor redColor]; 
    

    而且這樣的:

    - (void)tabBarController:(UITabBarController *)controller willBeginCustomizingViewControllers:(NSArray *)viewControllers { 
    UIView *editView = [controller.view.subviews objectAtIndex:1]; 
    UINavigationBar *modalNavBar = [editView.subviews objectAtIndex:0]; 
    modalNavBar.tintColor = [UIColor redColor]; 
    

    }

    不只是沒有或崩潰的barTintColor,因爲它 「不能設置barTintColor上的UILabel」 。但我不太清楚如何檢索不同的控件來設置它們的顏色值。

  • 回答

    2

    我找到了答案。我應該已經登錄edit_views然後我會看到,該navigationBar在索引1和不爲0然後在指數2到底有哪裏我不能設置正確的顏色UITabBarButtons ..

    最終的代碼看起來像這樣的:

    - (void)tabBarController:(UITabBarController *)tabBarController 
        willBeginCustomizingViewControllers:(NSArray *)viewControllers 
    { 
        UIView*   edit_views = [tabBarController.view.subviews objectAtIndex:1]; 
        UINavigationBar* bar  = [[edit_views subviews]objectAtIndex:1]; 
    
        bar.barTintColor = [UIColor redColor]; 
        bar.tintColor = [UIColor whiteColor]; 
        for (int i = 3; i < [edit_views.subviews count]; i++) 
        { 
         UIButton *button = [[edit_views subviews]objectAtIndex:i]; 
         button.tintColor = [UIColor redColor]; 
        } 
    } 
    
    3

    可以達到這樣的效果,而不使用UIAppearance以及設置窗口tintColor與UIView的層次亂搞。因此,您可以將此代碼放在您的application:didFinishLaunchingWithOptions:

    [self.window setTintColor:[UIColor redColor]]; 
    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]]; 
    [[UINavigationBar appearance] setBarTintColor:[UIColor redColor]]; 
    

    您還可以通過使用appearanceWhenContainedIn:如果你想在不同的視圖控制器導航欄的不同造型限制UIAppearance代碼。