Before the IOS7, Uitabbaritem pictures are fixed rendering as blue, want to change the color of the Uitabbaritem image must be customized, after the IOS7, has been updated, convenient for everyone to set the color, the following code!
1. Create Uitabbaritem default picture and selected picture
//First InterfaceChildviewcontroller *CHILDVC =[[Childviewcontroller Alloc]initwithnibname:nil Bundle:nil]; Uinavigationcontroller*childnav =[[Uinavigationcontroller ALLOC]INITWITHROOTVIEWCONTROLLER:CHILDVC]; //Uitabbaritem *childitem = [[Uitabbaritem alloc]init];Uitabbaritem *childitem = [[Uitabbaritem alloc]initwithtitle:@"Child Situation"Image:[uiimage imagenamed:@"about children default effects. PNG"] Tag:1]; Childitem.selectedimage= [[UIImage imagenamed:@"About Children check effect. PNG"] imagewithrenderingmode:uiimagerenderingmodealwaysoriginal]; Childnav.tabbaritem= ChildItem;
The best way to initialize is to use this
-(Instancetype) Initwithtitle: (NSString *) title Image: (UIImage *) image tag: (nsinteger) tag;
which
Childitem.selectedimage = [[UIImage imagenamed:@ ' about child selection effect. png'] Imagewithrenderingmode: Uiimagerenderingmodealwaysoriginal];
This is the time to set the selected picture, always keep the picture as it is not rendered blue.
Imagewithrenderingmode is a rendering mode of UIImage, coloring (Tint color) is one of the iOS7 interfaces. Set the rendering mode of the UIImage: Uiimage.renderingmode A significant change, you can set a UIImage Color to use the current view when rendering. UIImage added a read-only property: Renderingmode, corresponding to a new method: Imagewithrenderingmode:, It uses the Uiimagerenderingmode enumeration value to set the Renderingmode property of the picture. The enumeration contains the following values:
- Uiimagerenderingmodeautomatic//Adjusts the rendering mode automatically based on the environment in which the picture is used and the drawing context in which it is located.
- Uiimagerenderingmodealwaysoriginal//Always draws the original state of the picture without using tint Color.
- Uiimagerenderingmodealwaystemplate//Always draws a picture based on tint color, ignoring the color information of the picture.
The default value of the Renderingmode property is Uiimagerenderingmodeautomatic, which is whether uiimage uses tint color depending on where it is displayed.
2. Set the color of the title of Uitabbaritem not to be rendered
[[Uitabbaritem appearance] Settitletextattributes:[nsdictionary Dictionarywithobjectsandkeys:[uicolor Lightgraycolor], Uitextattributetextcolor, nil] forstate:uicontrolstatenormal]; [[Uitabbaritem appearance] Settitletextattributes: [Nsdictionary dictionarywithobjectsandkeys:[uicolor colorwithred:59.0/255.0 Green: 207.0/255.0 Blue:202.0/255.0 Alpha:1],uitextattributetextcolor, Nil]forstate:uicontrolstateselected];
The above sentence is set to the default color, the following when set the color of the selected font.
The following is the complete APPDELEGATE.M method:
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {Self.window=[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]; //First InterfaceChildviewcontroller *CHILDVC =[[Childviewcontroller Alloc]initwithnibname:nil Bundle:nil]; Uinavigationcontroller*childnav =[[Uinavigationcontroller ALLOC]INITWITHROOTVIEWCONTROLLER:CHILDVC]; //Uitabbaritem *childitem = [[Uitabbaritem alloc]init];Uitabbaritem *childitem = [[Uitabbaritem alloc]initwithtitle:@"Child Situation"Image:[uiimage imagenamed:@"about children default effects. PNG"] Tag:1]; Childitem.selectedimage= [[UIImage imagenamed:@"About Children check effect. PNG"] imagewithrenderingmode:uiimagerenderingmodealwaysoriginal]; Childnav.tabbaritem=ChildItem; //a second interfaceKkviewcontroller *CHATVC =[[Kkviewcontroller Alloc]initwithnibname:nil Bundle:nil]; Uinavigationcontroller*chatnav =[[Uinavigationcontroller ALLOC]INITWITHROOTVIEWCONTROLLER:CHATVC]; Uitabbaritem*chatitem = [[Uitabbaritem alloc]initwithtitle:@ "Chat"Image:[uiimage imagenamed:@"communication default. png"] Tag:2]; Chatitem.selectedimage= [[UIImage imagenamed:@"communication Select. PNG"] imagewithrenderingmode:uiimagerenderingmodealwaysoriginal]; Chatnav.tabbaritem=Chatitem; //a third interfaceToolsviewcontroller *TOOLVC =[[Toolsviewcontroller Alloc]initwithnibname:nil Bundle:nil]; Uinavigationcontroller*toolnav =[[Uinavigationcontroller ALLOC]INITWITHROOTVIEWCONTROLLER:TOOLVC]; Uitabbaritem*toolitem = [[Uitabbaritem alloc]initwithtitle:@"Tool Bar"Image:[uiimage imagenamed:@ " toolbardefault. png"] Tag:3]; Toolitem.selectedimage= [[UIImage imagenamed:@ " toolbarselect the. png"] imagewithrenderingmode:uiimagerenderingmodealwaysoriginal]; Toolnav.tabbaritem=Toolitem; //Fourth InterfacePersonviewcontroller *LOGINVC =[[Personviewcontroller Alloc]initwithnibname:nil Bundle:nil]; Uinavigationcontroller*loginnav =[[Uinavigationcontroller ALLOC]INITWITHROOTVIEWCONTROLLER:LOGINVC]; Uitabbaritem*loginitem = [[Uitabbaritem alloc]initwithtitle:@"Personal Center"Image:[uiimage imagenamed:@"Personal Center default. PNG"] Tag:4]; Loginitem.selectedimage= [[UIImage imagenamed:@"Personal Center Select. PNG"] imagewithrenderingmode:uiimagerenderingmodealwaysoriginal]; Loginnav.tabbaritem=Loginitem; [[Uitabbaritem appearance] Settitletextattributes:[nsdictionary Dictionarywithobjectsandkeys:[uicolor Lightgraycolor], Uitextattributetextcolor, nil] forstate:uicontrolstatenormal]; [[Uitabbaritem appearance] Settitletextattributes: [Nsdictionary D Ictionarywithobjectsandkeys:[uicolor colorwithred:59.0/255.0Green207.0/255.0Blue202.0/255.0Alpha1],uitextattributetextcolor, nil]forstate:uicontrolstateselected]; Uitabbar*tb=[[uitabbar Alloc] Initwithframe:cgrectmake (0.0,0.0,320.0,96.0) ] ; [Self.window ADDSUBVIEW:TB]; Uitabbarcontroller*TBC =[[Uitabbarcontroller alloc]init]; Tbc.viewcontrollers=@[childnav,chatnav,toolnav,loginnav]; Self.window.rootViewController =TBC;Self.window.backgroundColor =[Uicolor Whitecolor];[Self.window makekeyandvisible]; returnYES;}
In doubt, please leave a message to communicate with each other!
IOS7 no need to customize after, change the Uitabbaritem picture text color