IOS changes tabbar Image Rendering-do not let tabbat have blue rendering and modify text,

Source: Internet
Author: User

IOS changes tabbar Image Rendering-do not let tabbat have blue rendering and modify text,
Method 1: code implementation this requires a lot of code. Every controller needs to write UIImage * image = [UIImage imageNamed: @ "tabBar_friendTrends_click_icon"]; // key code for rendering at the bottom of the tabbar: image = [image imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal]; vc01.tabBarItem. selectedImage = image; change the text style, size, color NSMutableDictionary * atts = [dictionary]; // change the text size atts [NSFontAttributeName] = [UIFont systemFontOfSize: 12]; // change the text color. atts [NSForegroundColorAttributeName] = [UIColor darkGrayColor]; NSMutableDictionary * selectedAtts = [NSMutableDictionary dictionary];
SelectedAtts [NSFontAttributeName] = [UIFont systemFontOfSize: 12];
SelectedAtts [NSForegroundColorAttributeName] = [UIColor greenColor]; [vc01.tabBarItem setTitleTextAttributes: selectedAtts forState: UIControlStateSelected]; method 2 in Assets. after the changes in the xcassets folder are made, no code is required and will be applied to the specific appearance attribute in all controllers. // you can use appearance to set the text attribute of all UITabBarItem in a unified manner. // The text attribute with UI_APPEARANCE_SELECTOR method, you can use appearance to agree to set text attribute cases such as UITabBarItem;
NSMutableDictionary * atts = [NSMutableDictionary dictionary];
Atts [NSFontAttributeName] = [UIFont systemFontOfSize: 12];
Atts [NSForegroundColorAttributeName] = [UIColor grayColor];

NSMutableDictionary * selectedAtts = [NSMutableDictionary dictionary];
SelectedAtts [NSFontAttributeName] = atts [NSFontAttributeName]; selectedAtts [NSForegroundColorAttributeName] = [UIColor darkGrayColor]; // you only need to change it here, change all text to UITabBarItem * item = [UITabBarItem appearance];
[Item setTitleTextAttributes: atts forState: UIControlStateNormal];
[Item setTitleTextAttributes: selectedAtts forState: UIControlStateSelected];

// Add a sub-Controller
UIViewController * vc01 = [[UIViewController alloc] init];
Vc01.view. backgroundColor = [UIColor redColor];
Vc01.tabBarItem. title = @ "excellent ";
Vc01.tabBarItem. image = [UIImage imageNamed: @ "tabBar_essence_icon"];
UIImage * image = [UIImage imageNamed: @ "tabBar_friendTrends_click_icon"];
// Key code for rendering at the bottom of the tabbar: image = [image imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal]; vc01.tabBarItem. selectedImage = image; // Add the Controller to UITabBarController to [self addChildViewController: vc01];
UIViewController * vc02 = [[UIViewController alloc] init];
Vc02.tabBarItem. title = @ "New Post ";
Vc02.tabBarItem. image = [UIImage imageNamed: @ "tabBar_new_click_icon"];
Vc02.tabBarItem. selectedImage = [UIImage imageNamed: @ "tabBar_new_click_icon"];
Vc02.view. backgroundColor = [UIColor cyanColor];
[Self addChildViewController: vc02];

UIViewController * vc03 = [[UIViewController alloc] init];
Vc03.view. backgroundColor = [UIColor blueColor];
Vc03.tabBarItem. title = @ "follow ";
Vc03.tabBarItem. image = [UIImage imageNamed: @ "tabBar_friendTrends_icon"];
Vc03.tabBarItem. selectedImage = [UIImage imageNamed: @ "tabBar_friendTrends_click_icon"];
[Self addChildViewController: vc03];

UIViewController * vc04 = [[UIViewController alloc] init];
Vc04.tabBarItem. title = @ "me ";
Vc04.tabBarItem. image = [UIImage imageNamed: @ "tabBar_me_icon"];
Vc04.tabBarItem. selectedImage = [UIImage imageNamed: @ "tabBar_me_click_icon"];
Vc04.view. backgroundColor = [UIColor yellowColor]; [self addChildViewController: vc04];

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.