创建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]];

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 1.不可变数组转变为可变数组声明实例变量的数组 必须记得实现 对于遍历数组找到对象后 如果还需要查找 记得先结束 ...
    小新xin阅读 1,022评论 0 1
  • 1.自定义控件 a.继承某个控件 b.重写initWithFrame方法可以设置一些它的属性 c.在layouts...
    圍繞的城阅读 3,691评论 2 4
  • 对nextVC 进行属性赋值后,执行push跳转,方法的执行顺序: A跳转到B代码顺序执行:B的init 方法;(...
    進无尽阅读 681评论 1 6
  • 一点说明:本文中“导航控制器”区别于“视图控制器”存在 UINavigationController UINavi...
    WeiHing阅读 5,154评论 0 11
  • 人必须进入关系才能求得自身的意义和价值,否则天堂也会是地狱。但进入关系的彼此难得三观一致,人生的方向和目的地也就不...
    山贼爷阅读 633评论 0 0

友情链接更多精彩内容