创建navgationController和底部工具栏

先在AppDelegate中创建navgationController作为根视图控制器

self.window= [[UIWindowalloc]initWithFrame:[UIScreenmainScreen].bounds];

VCRoot* root = [[VCRootalloc]init];

//导航控制器一定要有一个根视图控制器

UINavigationController* nav = [[UINavigationControlleralloc]initWithRootViewController:root];

//将window的根视图控制器设置为导航

self.window.rootViewController= nav;

[self.windowmakeKeyAndVisible];


然后在根视图控制器中就可以获取到navgationItem(当前页)和navgationController(导航控制器)可以在当前页的导航中增加uibarbuttonitem来调用事件使用导航控制器来推页和退回

self.navigationItem.title=@"根视图";

self.view.backgroundColor= [UIColorwhiteColor];

UIBarButtonItem* rightBtn = [[UIBarButtonItemalloc]initWithTitle:@"下一个"style:UIBarButtonItemStyleDonetarget:selfaction:@selector(pressNext)];

rightBtn.tintColor= [UIColorblueColor];

self.navigationItem.rightBarButtonItem= rightBtn;

- (void)pressNext{

[self.navigationControllerpushViewController:vsanimated:YES];

}


Toolbar底部工具栏

self.navgation.toolbarhidden = NO;

默认是隐藏底部工具栏的 如果要打开需要设置为no

然后在self.toolbarItems = @[]

属性传入一个按钮数组

UIButton* bt = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];

UIBarButtonSystemItemFixedSpace是占位按钮 空白的 可以为负数

UIBarButtonSystemItemFlexibleSpace也是占位按钮 是等分类似space-around

UIBarButtonItem* ub = [[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];

ub.width= -20;

bt.frame=CGRectMake(0,0,60,40);

[btsetTitle:@"hello"forState:UIControlStateNormal];

self.toolbarItems=@[[[UIBarButtonItemalloc]initWithTitle:@"hello"style:UIBarButtonItemStyleDonetarget:selfaction:nil],

ub

,[[UIBarButtonItemalloc]initWithCustomView:bt]];

你可能感兴趣的:(创建navgationController和底部工具栏)