How do I change background color of UITabItem when item is selected

前端 未结 11 1065
暖寄归人
暖寄归人 2021-02-01 19:15

I would like a different background color when the user selects a tab bar item than when it is unselected.

相关标签:
11条回答
  • 2021-02-01 19:47

    Please refer below URL's.

    Changing Tint / Background color of UITabBar

    How To Change Tab bar color in Xcode

    hope this will help you..

    try this to change tabbar item color but it only work in ios5.

    if ([UITabBar instancesRespondToSelector:@selector(setSelectedImageTintColor:)])
    {
        [tabBarController.tabBar setSelectedImageTintColor:[UIColor redColor]];
    }
    
    0 讨论(0)
  • 2021-02-01 19:50

    Put this in your AppDelegate.m file:

     - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
                // Override point for customization after application launch.
    
                [UITabBar appearance].selectionIndicatorImage = [UIImage imageNamed:@"activeTabBackgroundImage"];
    
    
                return YES;
            }
    
    0 讨论(0)
  • 2021-02-01 19:52

    Answer in swift 4:

    setSelectedImageTintColor is deprecated on iOS 8.

    Instead use this :

    self.tabBar.tintColor = UIColor.white

    0 讨论(0)
  • 2021-02-01 19:53

    In Swift

    UITabBar.appearance().selectionIndicatorImage = UIImage(named: "tabSelected")
    

    with an image tabSelected@2x.png of size 98x98 pixels

    0 讨论(0)
  • 2021-02-01 19:54

    You can use tintcolor.

    [[UITabBar appearance] setSelectedImageTintColor:[UIColor redColor]];
    

    In AppDelegate.m, put the following code after // Override point for customization after application launch.

    0 讨论(0)
提交回复
热议问题