About iOS7-8 systems UITabBarController, uitabbarcontroller

Source: Internet
Author: User

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];
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.