本兇學(xué)習(xí)內(nèi)容:
1.導(dǎo)航欄和工具欄的概念
2.導(dǎo)航瘭和工具欄的屬性
barStyle:導(dǎo)航欄風(fēng)格
barTintColor:導(dǎo)航欄顏色
tintColor:導(dǎo)航欄風(fēng)格顏色
toolbarItems:工具欄元素?cái)?shù)組
UIBarItemFlexibleSpace:自動(dòng)調(diào)整距離按鈕
3.導(dǎo)航欄和工具欄的使用
創(chuàng)建一個(gè)根視圖命名為VCRoot
【VCRoot.m】
#import "VCRoot.h"
#import"VCSecond.h"
@interface VCRoot()
@end
@implementation VCRoot
-(void)viewDidLoad{
[super viewDidLoad];
self.view.backgroundColor=[UIColor yellowColor];
//設(shè)置導(dǎo)航欄風(fēng)格顏色嘹黔,UIBarStyleBlack:黑色風(fēng)格瓣蛀,UIBarStyleDefault默認(rèn)風(fēng)格
self.navigationController.navigationBar.barStyle=UIBarStyleDefault:
//將風(fēng)格設(shè)置為不透明
self.navigationController.navigationBar.translucent=NO;
//設(shè)置導(dǎo)航欄顏色
self.navigationController.navgationBar.barTintColor=[UIColor redColor];
//設(shè)置導(dǎo)航 元素項(xiàng)目按扭的風(fēng)格顏色
self.navigationController.navigationBar.tintColor=[UIColor blackColor];]
//隱藏導(dǎo)航欄,兩個(gè)使用任何一個(gè)都可以,默認(rèn)值都是NO
//self.navigationController.navigationBar.hidden=YES;
self.navigationController.navigationBarHidden=YES;
self.title=@"根視圖";
UIBarButton* btn=[[UIBarButtonItem alloc]initWithTitle:@“右側(cè)按扭”style:UIBarButtonItemStylePlan target:nil aciton:nil];
self.navigationItem.rightBarButtonItem=btn;
//實(shí)現(xiàn)工具欄對(duì)象王带,默認(rèn)工具欄時(shí)隱藏的
self.navigationController.toolbarHidden=no;
//設(shè)置工具欄透明度
self.navigationController.toolbar.translucents=NO;
UIBarButtonItem* btn01=[[UIBarButtonItem alloc]initWithTitle:@"left"style:UIBarButtonItemStylePlan target:nil action:nil];
UIBarButtonItem* btn02=[[UIBarButtonItem alloc]initWithBarButtonSytemItem:UIBarButtonSystemItemCamera traget:self action:@selction(pressNext)];
UIButton* btnImage=[UIButton buttonWithType:UIButtonTypeCuston];
[btnImage setImage:[UIImage imageNamed:@"btn02,jpg"]forSate:UIControlStateNormal];
btnImage.frame=CGRectMake(0,0,60;60);
//因定寬度占位按鈕
UIBarButtonItem* btnF01=[[UIBarButton alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
btnF01.width=90;
//創(chuàng)建自動(dòng)計(jì)算寬度按鈕
UIBarButtonItem* btnF02=[[UIBarttonItem alloc]initWithBarButtonSystemItem]:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem* btn03=[UIBarButtonItem alloc]initWithCustonView:btnImage];
//按鈕數(shù)組創(chuàng)建
NSArray( arrayBtns=[NSArray arrayWithObjects:btn01,btnF02,btn02,btnF02,btn03,nil];
self.toolbarItems=arrayBtns;
}
-(void)pressNext{
VCSecond* vc=[[VCSecond alloc]init];
[self.navigationController pushViiewController:vc animated:YES];
}
創(chuàng)建一個(gè)子視圖命名VCSecend
【AppDelegate.m】
#import"AppDelegate.h"
#import"VCroot.h"
@interface AppDelegate()
@end
@implementation AppDelegate
-(BOOL)application:(UIApplication *)application didFinishLaunchingWighOptions:(NSDictionary *)launchOptions{
self.window=[[UIWindow alloc]initWithFrame:[UIScreen aminScreen].bounds];
UINavigationController* nav=[[UINavigationController alloc]initVithRootViewController:[[VCRoot alloc]init]];
self.window.rootViewController=nav;
[self.window makeKeyAndVisible];
return YES;
}