UINavigationController 导航栏

作者: 阿年同学 | 来源:发表于2016-07-11 23:14 被阅读100次
  • 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"; //文本显示在导航栏按钮(在最上方)
显示网址的样子 动画效果

相关文章

网友评论

    本文标题:UINavigationController 导航栏

    本文链接:https://www.haomeiwen.com/subject/zrmjjttx.html