//APPDELEGATE.M
#import "AppDelegate.h"
#import "ViewController.h"
@interface appdelegate()
@end
@implementationappdelegate
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {
CGRect rect = [UIScreen mainscreen].bounds;//size of screen
UIWindow *w = [[UIWindow alloc]initwithframe:rect];//Create a new page and fill the entire display with the newly created page
W.backgroundcolor = [Uicolor Redcolor];//Set the color of the newly created page to red
[w makekeyandvisible];//To display the effect of the settings on the page
Self.window = W;//Make start setting not immediately system to destroy
Viewcontroller *v = [[Viewcontroller alloc]init];//Create another page
Uinavigationcontroller *nav =[[uinavigationcontroller Alloc]initwithrootviewcontroller:v];//Initial draw navigation page and create
UIImage *image = [UIImage imagenamed:@ "a"];//Assign a value to the image you want to use and create
[Nav.navigationbar setbackgroundimage:image Forbarmetrics:uibarmetricsdefault];//Add a picture to the navigation page
Nav.view.backgroundColor = [Uicolor colorwithred:0 green:1 blue:0 alpha:1];//Set the background color for the navigation page and use a ternary color to represent
V.view.backgroundcolor = [Uicolor Orangecolor];//Set the background color of the page to Orange
Self.window.rootViewController = nav;//To display the created navigation page on the first page
return YES;
}
//VIEWCONTROLLER.M
#import "ViewController.h"
#import "SecondViewController.h"
@interface Viewcontroller ()
@end
@implementation Viewcontroller
Automatic call after view loading is complete
-(void) Viewdidload {
[Super Viewdidload];
Self.title = @ "AAA";//The first method displays labels on the navigation page
Self.navigationItem.title = @ "AAA";//The second method displays labels on the navigation page
1.
Uibarbuttonitem *leftitem = [[Uibarbuttonitem alloc] initwithtitle:@ "left" Style:uibarbuttonitemstyleplain target: Self action: @selector (didleftclicked)];//
2.
UIImage *img = [UIImage imagenamed:@ "Back"];//Add picture and initialize
Uibarbuttonitem *leftitem2 = [[Uibarbuttonitem alloc] initwithimage:img style:uibarbuttonitemstyledone target:self A Ction: @selector (didleftclicked)];//
3. Use a custom control as the left item
Uiimageview *imgview = [[Uiimageview alloc] initwithimage:img];//
UIButton *leftbtn = [UIButton buttonwithtype:uibuttontypecustom];//Create a button
[Leftbtn setimage:img forstate:uicontrolstatenormal];//load the picture on the button
Only size has effect
Leftbtn.frame = CGRectMake (0, 0, 40, 40);//The position size of the button
Uibarbuttonitem *leftitem3 = [[Uibarbuttonitem alloc] initwithcustomview:leftbtn];//
Set navigation bar Left/right button
Self.navigationItem.rightBarButtonItems = @[leftitem3];//
Uiimageview *imgview = [[Uiimageview alloc] initwithimage:img];//
Self.navigationItem.titleView = imgview;//
The navigation bar is divided into 3 sections
0. Self.navigationController.navigationBar
1. Self.navigationItem.leftBarButtonItem (s)
2. Self.navigationItem.rightBarButtonItem (s)
3. Self.navigationItem.title (View)
UIButton *btn = [UIButton Buttonwithtype:uibuttontypesystem];//Create a button
Set captions for different states
[Btn settitle:@ "button" forstate:uicontrolstatenormal];//In the normal Time button is displayed as "button"
[Btn settitle:@ "highlight" forstate:uicontrolstatehighlighted];//button appears as "Highlight" when button is clicked
[Btn Setbackgroundcolor:[uicolor Redcolor];//The first method means that the background color of the button is red
Btn.backgroundcolor = [Uicolor Redcolor];///The second method indicates that the background color of the button is red
[Btn addtarget:self Action: @selector (didclicked) forcontrolevents:uicontroleventtouchupinside];//Click the button to execute the method name and type of execution
Btn.frame = CGRectMake (0, 64, 100, 100);//Set location and size
[Self.view ADDSUBVIEW:BTN];//Display button
}
-(void) didleftclicked//Button execution method
{
NSLog (@ "%s", __pretty_function__);
}
-(void) didclicked//Button execution method
{
NSLog (@ "%s", __func__);
Secondviewcontroller *viewctrl = [[Secondviewcontroller alloc] init];//
ViewCtrl.view.backgroundColor = [Uicolor orangecolor];//
[Self Presentviewcontroller:viewctrl animated:yes completion:nil];//null
[Self.navigationcontroller Pushviewcontroller:viewctrl animated:yes];//
//All pages managed by the navigation controller will have a pointer to the navigation controller Navigationcontroller
NSLog (@ "2:%p", self.navigationcontroller);//
}
@end
#import "SecondViewController.h"
@interface Secondviewcontroller ()
@end
@implementation Secondviewcontroller
-(void) Viewdidload {
[Super Viewdidload];
Self.title = @ "Second";//The navigation page title in the second page is set to this
Self.view.backgroundColor = [Uicolor Purplecolor];//Set the background color of the page
UIButton *btn = [UIButton Buttonwithtype:uibuttontypesystem];//Set a button
[BTN settitle:@ "second button" forstate:uicontrolstatenormal];//Set a general button and name the second button
[Btn addtarget:self Action: @selector (didclicked:) forcontrolevents:uicontroleventtouchupinside];//This button will execute its own didclicked method
btn.frame = CGRectMake (100, 100, 200, 50);//Set the position of the page where the button is located
[Self.view ADDSUBVIEW:BTN];//Set button to load on the page
NSLog (@ "BTN 1:%p", BTN);
}
-(void) didclicked: (UIButton *) Sender//button The method to be executed
{
NSLog (@ "%s", __func__);
NSLog (@ "BTN 2:%p", sender);
[Self.navigationcontroller Popviewcontrolleranimated:yes];//Will jump to the previous page
}
iOS navigation page