About iOS7-8 systems UITabBarController, uitabbarcontroller
IOS9 is coming soon. The UITabBarController of the system recently used for the project. Let's just mark the problem.
The default UITabBarController can be set using storyboard.
The following code sets the tabbar image and color.
1. tabbar background color or background image (Gray effect)
tabBarController.tabBar.backgroundImage = [UIImage imageNamed:@"tabbar_unselected"];
This image can be a line chart with a width of 2 pixels and a height of 98.
2. Set the background color or background image of the selected item (, blue effect)
UIImage* selectedImage = [UIImage imageNamed:@"tabbar_select"]; selectedImage = [selectedImage resizableImageWithCapInsets:UIEdgeInsetsZero]; tabBarController.tabBar.selectionIndicatorImage = selectedImage;
The image here can also be a line chart with a width of 2 pixels and a height of 98, just like the background image above.
SelectedImage = [selectedImage resizableImageWithCapInsets: UIEdgeInsetsZero];
To fill the image to be set with a line chart
3. Set the image color, font color, and font size.
NSMutableDictionary * textAttrs = [NSMutableDictionary dictionary]; textAttrs [identifier] = [UIColor whiteColor]; textAttrs [NSFontAttributeName] = [UIFont systemFontOfSize: 12.f];
MLNavigationController * oneController = [[MLNavigationController alloc] initWithRootViewController: VC1];
OneController. tabBarItem. title = @ "Homepage ";
OneController. tabBarItem. image = [[UIImage imageNamed: @ "tabbar_home"] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal];
OneController. tabBarItem. selectedImage = [[UIImage imageNamed: @ "tabbar_home"] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal];
[OneController. tabBarItem setTitleTextAttributes: textAttrs forState: UIControlStateNormal];
My requirement is to set the image and color to white in both the selected and unselected states.
3.1 font color settings
You can double-click the key value of the textAttrs dictionary to view the options you want to set. Note the following:
-(Void) setTitleTextAttributes :( NSDictionary *) attributes forState :( UIControlState) state NS_AVAILABLE_IOS (5_0) UI_APPEARANCE_SELECTOR;
In this method, only three types can be set: UIControlStateNormal, UIControlStateSelected, and UIControlStateDisabled.
3.2 image color settings
Image you will find that an image method is used
-(UIImage *) imageWithRenderingMode :( UIImageRenderingMode) renderingMode NS_AVAILABLE_IOS (7_0 );
This method tells the system to cancel rendering and use the original image color.
In this way, you can use the selectedImage and image provided by you to set it.
oneController.tabBarItem.image = [[UIImage imageNamed:@"tabbar_home"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
oneController.tabBarItem.selectedImage = [[UIImage imageNamed:@"tabbar_home"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];