Create tanbar for iOS7 story Edition
In ios7, the method setFinishedSelectedImage: withFinishedUnselectedImage: has been discarded. Therefore, if you set selectImage and image of tabBarItem directly, the image cannot be displayed.
This is obviously different from the image you want first.
The other selected status is white, so it can be seen from the above that it is different. Next, let's take a look at how to write the desired effect and effect.
If you do not create one, tabbarViewController will be created by everyone. The detailed settings are described below.
UITabBar *tabBar = self.tabBar; UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0]; UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1]; UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2]; UITabBarItem *tabBarItem4 = [tabBar.items objectAtIndex:3]; UITabBarItem *tabBarItem5 = [tabBar.items objectAtIndex:4];
Create five uitabbaritems, and then set the image of the Item.
UIImage *tabBarItem1Image = [UIImage imageNamed:@"11"]; UIImage *imgS1Image =[UIImage imageNamed:@"11s"]; tabBarItem1.selectedImage = [tabBarItem1Image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; tabBarItem1.image = [imgS1Image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; UIImage *tabBarItem2Image = [UIImage imageNamed:@"12"]; UIImage *imgS2Image =[UIImage imageNamed:@"12s"]; tabBarItem2.selectedImage = [tabBarItem2Image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; tabBarItem2.image = [imgS2Image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; UIImage *tabBarItem3Image = [UIImage imageNamed:@"13"]; UIImage *imgS3Image =[UIImage imageNamed:@"13s"]; tabBarItem3.selectedImage = [tabBarItem3Image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; tabBarItem3.image = [imgS3Image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; UIImage *tabBarItem4Image = [UIImage imageNamed:@"14"]; UIImage *imgS4Image =[UIImage imageNamed:@"14s"]; tabBarItem4.selectedImage = [tabBarItem4Image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; tabBarItem4.image = [imgS4Image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; UIImage *tabBarItem5Image = [UIImage imageNamed:@"15"]; UIImage *imgS5Image =[UIImage imageNamed:@"15s"]; tabBarItem5.selectedImage = [tabBarItem5Image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; tabBarItem5.image = [imgS5Image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
The above setting method is used after iOS7. coloring (Tint Color) is a major change in the iOS7 interface. You can set whether a UIImage uses the Tint Color of the current view during rendering. UIImage adds a read-only attribute: renderingMode, which corresponds to another method: imageWithRenderingMode:. It uses the UIImageRenderingMode enumeration value to set the renderingMode attribute of the image. This enumeration contains the following values:
UIImageRenderingModeAutomatic // automatically adjusts the rendering mode based on the image's use environment and drawing context.
UIImageRenderingModeAlwaysOriginal // always draws the original status of the image without using Tint Color.
UIImageRenderingModeAlwaysTemplate, // always draw an image based on Tint Color, ignoring the Color information of the image.
Next, modify the text of the item. The Code is as follows:
[[UITabBarItem appearance] setTitleTextAttributes :@ {tags: [UIFont fontWithName: @ "subtitle-Bold" size: 10.0f], tags: [UIColor orangeColor]} forState: UIControlStateNormal]; // [[UITabBarItem appearance] setTitleTextAttributes: @ {NSFontAttributeName: [UIFont fontWithName: @ "subtitle-Bold" size: 10.0f], Region: [UIColor greenColor]} forState: UIControlStateSelected]; // select
Set the background image and the image when the item is selected as follows
// Set the image below the selected item? TabBar. selectionIndicatorImage = [UIImage imageNamed: @ "select_bg"]; // set the background image of tabBar? Self. tabBar. backgroundImage = [UIImage imageNamed: @ "show_bg"];
Success!