IOS custom properties for various bar

Source: Internet
Author: User

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

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.