Navigationcontroller's navigation bar is set when iOS uses pure code to write programs

Source: Internet
Author: User

We all know that if you use storyboard to set the navigation bar is very easy, click on the left and right item, enter the next interface, the navigation bar color is the same as the previous layer is the same, with pure code when written, can be in the current controller, And from the current controller into the next controller are implemented in code to control the navigation bar, but each time the code is written to set, it is cumbersome, so you can:

Create a Maintabbarcontroller class that is completed in APPDELEGATE.M:

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {

Override point for customization after application launch.

Self.window = [[UIWindow alloc] Initwithframe:[uiscreen mainscreen].bounds];

Self.window.rootViewController = [[Maintabbarcontroller alloc] init];

[Self.window makekeyandvisible];

return YES;

}

And then, inside the MAINTABBARCONTROLLER.M,

-(void) Viewdidload {

[Super Viewdidload];

[Self SETUPALLCHILDVC];

}

-(void) SETUPALLCHILDVC

{

There are several interfaces that set several

Mapviewcontroller *HOMEVC = [[Hfmapviewcontroller alloc] init];

[Self SETUPONECHILDVCWITHVC:HOMEVC image:@ map-Home "selectedimage:@" Map Selected-Home "title:@" map "];

Appointmentviewcontroller *APPOINTMENTVC = [[Hfappointmentviewcontroller alloc] init];

[Self SETUPONECHILDVCWITHVC:APPOINTMENTVC image:@ "appointment-Home" selectedimage:@ "Appointment selected-Home" title:@ "appointment"];

}

-(void) SETUPONECHILDVCWITHVC: (Uiviewcontroller *) Vc Image: (NSString *) image selectedimage: (NSString *) selectedimage Title: (NSString *) title

{

Mainnavigationcontroller *nav = [[Mainnavigationcontroller alloc] INITWITHROOTVIEWCONTROLLER:VC];

UIImage *myimage = [UIImage imagenamed:image];

MyImage = [MyImage imagewithrenderingmode:uiimagerenderingmodealwaysoriginal];

Tabbaritem, is the system provides the model, specifically responsible for the Tabbar button on the text and image display

Vc.tabBarItem.image = MyImage;

UIImage *myselectedimage = [UIImage imagenamed:selectedimage];

Myselectedimage = [Myselectedimage imagewithrenderingmode:uiimagerenderingmodealwaysoriginal];

Vc.tabBarItem.selectedImage = Myselectedimage;

Vc.tabBarItem.title = title;

[Self addchildviewcontroller:nav];

}

As long as the navigation bar is required, the current controller can be set to mainnavigationcontroller the same as the attempted controller

Navigationcontroller's navigation bar is set when iOS uses pure code to write programs

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.