本凶学习内容:
1.导航栏和工具栏的概念
2.导航瘭和工具栏的属性
barStyle:导航栏风格
barTintColor:导航栏颜色
tintColor:导航栏风格颜色
toolbarItems:工具栏元素数组
UIBarItemFlexibleSpace:自动调整距离按钮
3.导航栏和工具栏的使用
创建一个根视图命名为VCRoot
【VCRoot.m】
#import "VCRoot.h"
#import"VCSecond.h"
@interface VCRoot()
@end
@implementation VCRoot
-(void)viewDidLoad{
[super viewDidLoad];
self.view.backgroundColor=[UIColor yellowColor];
//设置导航栏风格颜色,UIBarStyleBlack:黑色风格,UIBarStyleDefault默认风格
self.navigationController.navigationBar.barStyle=UIBarStyleDefault:
//将风格设置为不透明
self.navigationController.navigationBar.translucent=NO;
//设置导航栏颜色
self.navigationController.navgationBar.barTintColor=[UIColor redColor];
//设置导航 元素项目按扭的风格颜色
self.navigationController.navigationBar.tintColor=[UIColor blackColor];]
//隐藏导航栏,两个使用任何一个都可以,默认值都是NO
//self.navigationController.navigationBar.hidden=YES;
self.navigationController.navigationBarHidden=YES;
self.title=@"根视图";
UIBarButton* btn=[[UIBarButtonItem alloc]initWithTitle:@“右侧按扭”style:UIBarButtonItemStylePlan target:nil aciton:nil];
self.navigationItem.rightBarButtonItem=btn;
//实现工具栏对象,默认工具栏时隐藏的
self.navigationController.toolbarHidden=no;
//设置工具栏透明度
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;
//创建自动计算宽度按钮
UIBarButtonItem* btnF02=[[UIBarttonItem alloc]initWithBarButtonSystemItem]:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem* btn03=[UIBarButtonItem alloc]initWithCustonView:btnImage];
//按钮数组创建
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];
}
创建一个子视图命名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;
}