How do I change background color of UITabItem when

2019-03-11 00:47发布

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

11条回答
干净又极端
2楼-- · 2019-03-11 01:02

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]];
}
查看更多
Viruses.
3楼-- · 2019-03-11 01:03

Currently in Xcode 8.3.2 you can do it inside the storyboard using an image that will represent the actual background.

Select the tab bar inside your tab bar controller:

enter image description here

Inside the Utilities choose the Attributes Inspector and change the selection background image:

enter image description here

查看更多
聊天终结者
4楼-- · 2019-03-11 01:05

if you use a storyboard or xibs, click "Tab Bar" and add "selectedImageTintColor" path into the Key Path Attributes tag. Like this :

enter image description here

查看更多
霸刀☆藐视天下
5楼-- · 2019-03-11 01:14

In Swift

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

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

查看更多
Viruses.
6楼-- · 2019-03-11 01:17

Put this in the Appdelegate.m in application didFinishLaunchingWithOptions

UIImage *whiteBackground = [UIImage imageNamed:@"whiteBackground"];
[[UITabBar appearance] setSelectionIndicatorImage:whiteBackground];
查看更多
你好瞎i
7楼-- · 2019-03-11 01:18

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;
        }
查看更多
登录 后发表回答