A. Text buttons on both sides of the navigation bar1. Requirements: Text buttons on both sides of the navigation bar Unified style Normal style: Orange Highlight style: Red not available style: Bright Gray shadow: No Font Size: Github:https://github.com/hellovoidworld/hvwweibo 2. To implement the effect default style: Uniform usage style: 3. Ideas
- Set one by one when you create the item: Code Super redundant
- Extract create public parent class: slightly better choice, but inherit this common parent class controller, you can not operate it to inherit the system comes with the Controller class, causing great hidden trouble. The controller in iOS does not recommend extracting the common parent class, preferably inheriting the system's own controller directly.
- Use theme appearance to set all Uibarbuttonitem styles uniformly: Adopt! Implemented once in a custom Uinavigationcontroller class initialization method, you can change all barbuttonitem styles that use this class
4. Implement HVWNAVIGATIONVIEWCONTROLLER.M:
1 /** Called when class is initialized*/2+ (void) Initialize {3 //Initialize the navigation bar style4 [self initnavigationbartheme];5 6 //Initialize the navigation bar item style7 [self initbarbuttonitemtheme];8 }9 Ten /** The style of the navigation bar item is set uniformly One * Because it is possible to modify all Navivationbar styles with the theme appearence, you can use the class method A */ -+ (void) Initbarbuttonitemtheme { - //set the navigation bar to modify the style of all Uinavigationbar theUibarbuttonitem *appearance =[Uibarbuttonitem appearance]; - - //set the style in the Noraml state -Nsmutabledictionary *normaltextattr =[Nsmutabledictionary dictionary]; + //Font Size -Normaltextattr[nsfontattributename] = [Uifont systemfontofsize: the]; + //Font Color ANormaltextattr[nsforegroundcolorattributename] =[Uicolor Orangecolor]; at //set to Normal style - [appearance settitletextattributes:normaltextattr forstate:uicontrolstatenormal]; - - //set the style in the highlighted State -Nsmutabledictionary *highlightedtextattr =[Nsmutabledictionary dictionarywithdictionary:normaltextattr]; - //Font Color inHighlightedtextattr[nsforegroundcolorattributename] =[Uicolor Redcolor]; - //set to Normal style to [appearance settitletextattributes:highlightedtextattr forstate:uicontrolstatehighlighted]; + - //set the style in the disabled state theNsmutabledictionary *disabledtextattr =[Nsmutabledictionary dictionarywithdictionary:normaltextattr]; * //Font Color $Disabledtextattr[nsforegroundcolorattributename] =[Uicolor Lightgraycolor];Panax Notoginseng //set to Normal style - [appearance settitletextattributes:disabledtextattr forstate:uicontrolstatedisabled]; the +}
B. Setting the navigation bar style 1. Requirements:
- Unified display text color: Black
- Text Shadow: Forbidden
- Font Size: 20
2. Ideas: With "a" 3. Realization: With "a" HVWNAVIGATIONVIEWCONTROLLER.M:
1 /** Set navigation bar style uniformly*/2+ (void) Initnavigationbartheme {3 //use Appearence (theme) settings to uniformly modify all navigation bar Styles4Uinavigationbar *appearance =[Uinavigationbar appearance];5 6 //To unify the iOS6 and IOS7,IOS6, you need to set the navigation bar background to simulate the iOS7 effect.7 if(!iOS7) {8[Appearance setbackgroundimage:[uiimage imagewithnamed:@"Navigationbar_background"] Forbarmetrics:uibarmetricsdefault];9 }Ten One //Setting Properties ANsmutabledictionary *attr =[Nsmutabledictionary dictionary]; - //Set Font -Attr[nsforegroundcolorattributename] =[Uicolor Blackcolor]; theAttr[nsfontattributename] = [Uifont systemfontofsize: -]; - //Remove the text shadow and set the shadow offset to 0 -Nsshadow *shadow =[[Nsshadow alloc] init]; -Shadow.shadowoffset =Cgsizezero; +Attr[nsshadowattributename] =Shadow; - + [appearance settitletextattributes:attr]; A}
[iOS Weibo project-1.1]-Set navigation bar theme (Unified style)