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