how to change UITabbar selected color?

后端 未结 4 1470
礼貌的吻别
礼貌的吻别 2020-12-18 14:02

according to this post for now, Is apple will also reject this code?

and how to implement what apple will approve?

@interface UITabBar (ColorExtensi         


        
相关标签:
4条回答
  • 2020-12-18 14:40

    Yes, Apple will reject an app if you use that code.

    I just had an app rejected for using private API calls. Specifically "_updateView". And I used the exact same code as above.

    (If other people say that their app got approved with the same code it's just because it wasn't checked for use of private APIs.)

    0 讨论(0)
  • 2020-12-18 14:42

    I suggest instead of changing color why don't you use selected tabbaritem image, like In iOS 6 I have change the selected tabbatitem image like -

    in tabbar controller delegate method

    - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
    
    {
        if([tabBarController selectedIndex] == 0)
        {
            [viewController.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"selected.png"]withFinishedUnselectedImage:[UIImage imageNamed:@"unselect.png"]];
        }    
    }
    

    through this you can change your image.

    Or you can use directly in your view controllers init(or ViewWillAppear) method, like

            [viewController.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"selected.png"]withFinishedUnselectedImage:[UIImage imageNamed:@"unselect.png"]];
    
    0 讨论(0)
  • 2020-12-18 15:02

    for iOS 10 (or higher):

    To set selected color just set:

    let tabBarAppearace = UITabBar.appearance()
    tabBarAppearace.tintColor = UIColor.nowYouBlue
    

    Above will work for all iOS version currently supported, but to change unselected color:

        if #available(iOS 10.0, *) {
            tabBarAppearace.unselectedItemTintColor = UIColor.red
        } else {
            // Fallback on earlier versions
        }
    

    Above code will look like this on iOS 10.

    0 讨论(0)
  • 2020-12-18 15:03
    [[UITabBar appearance] setSelectedImageTintColor:[UIColor whiteColor]];
    
    0 讨论(0)
提交回复
热议问题