In iOS app development, often need to set the same theme for the navigation Bar and tab bar, one to set, it is too troublesome, you can use all the navigation bar and tab bar in the app to agree to set the background, font and other properties.
For example: Create a public parent class that inherits from "Uinavigationcontroller", and then all Navigationcontroller in the app inherit Uinavigationcontroller, Through the class method in the Uinavigationcontroller class
Setting the navigation bar properties in initialize will work for all navigation bar controllers in the project
The sample code is as follows:
1+ (void) Initialize2 {3 4 #warningYou can modify the color of the buttons in Uitabbar by setting the Uitabbar theme5Uitabbar *tabbar =[Uitabbar appearance];6Nsmutabledictionary *tabattrs =[Nsmutabledictionary dictionary];7Tabattrs[uitextattributetextcolor] =[Uicolor Orangecolor];8 [TabBar settintcolor:[uicolor orangecolor];9 Ten //1 Setting Uinavigationbar OneUinavigationbar *navbar =[Uinavigationbar appearance]; A - - the //1.1 Setting the status bar -[UIApplication Sharedapplication].statusbarstyle =Uistatusbarstyleblackopaque; - - //1.2 Setting a background image +[NavBar setbackgroundimage:[uiimage Imagewithname:@"Navigationbar_background"] Forbarmetrics:uibarmetricsdefault]; - + A //1.3. Set the font atNsmutabledictionary *attrs =[Nsmutabledictionary dictionary]; -Attrs[uitextattributetextcolor] =[Uicolor Blackcolor]; -Attrs[uitextattributetextshadowoffset] = [Nsvalue valuewithcgsize:cgsizemake (0,0)]; -Attrs[uitextattributefont] = [Uifont systemfontofsize: -]; - - [NavBar settitletextattributes:attrs]; in - //2 Setting the navigation bar button theme toUibarbuttonitem *baritem =[Uibarbuttonitem appearance]; + //2.1 Setting the background map -[Baritem setbackbuttonbackgroundimage:[uiimage Imagewithname:@"Navigationbar_button_background"] Forstate:uicontrolstatenormal Barmetrics:uibarmetricsdefault]; the[Baritem setbackbuttonbackgroundimage:[uiimage Imagewithname:@"navigationbar_button_background_pushed"] forstate:uicontrolstatehighlighted Barmetrics:uibarmetricsdefault]; *[Baritem setbackbuttonbackgroundimage:[uiimage Imagewithname:@"navigationbar_button_background_disable"] forstate:uicontrolstatedisabled Barmetrics:uibarmetricsdefault]; $ //2.2 Setting font propertiesPanax NotoginsengNsmutabledictionary *itemattrs =[Nsmutabledictionary dictionary]; - theItemattrs[uitextattributetextcolor] = iOS7?[Uicolor Orangecolor]: [Uicolor blackcolor]; +Itemattrs[uitextattributetextshadowoffset] = [Nsvalue valuewithcgsize:cgsizemake (0,0)]; AItemattrs[uitextattributefont] = [Uifont systemfontofsize: -]; the [Baritem settitletextattributes:itemattrs forstate:uicontrolstatenormal]; +}
IOS custom properties for various bar