UINavigationController 导航栏

  • AppDelegate.m
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

RootViewController *root = [[RootViewController alloc] init];

//标题(中间位置)
root.title = @"首页";


//创建导航栏控制器
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:root];

self.window.rootViewController = navController;

[_window makeKeyAndVisible];







leftButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(selectLeft:)];

self.navigationItem.leftBarButtonItem = leftButton; // 左边的button

rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(selectRight:)];

self.navigationItem.rightBarButtonItem = rightButton; // 右边的button



AddViewController *add = [[AddViewController alloc] init]; // 右button点击事件
    
//修改字体啥的
self.navigationItem.title = @"返回";

[self.navigationController pushViewController:add animated:YES];
导航栏button样式
  • AddViewController.m
self.view.backgroundColor = [UIColor greenColor];

self.title = @"第二页";
首页

点击右上角的加号,会进入第二页。

第二页

点击返回,到第一页。

self.navigationItem.prompt = @"欢迎访问www.baidu.com"; //文本显示在导航栏按钮(在最上方)
显示网址的样子
动画效果
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容