导航栏最常见的例子就是返回按钮的所在

在AppDelegate.m中,代码布局最开始定义窗口的时候, _window.rootViewController就应该为一个UINavigationController

这里的UINavigationController,戳进定义发现它是UIViewcontroller的子类

而之前代码布局中这里用的rootController是UIViewcontroller

所以它之中也是像之前代码布局中的UIViewcontroller一样是包含多个controller的,所以作为rootController

//按我自己理解,UINavigationController就是一个带导航栏的特殊UIViewcontroller,我们用导航栏,就选择用它

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.

UINavigationController *rootNav = [[UINavigationController alloc]
initWithRootViewController:[[ViewController alloc]init]]; _window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
_window.rootViewController = rootNav;
[_window makeKeyAndVisible];
return YES;
}

导航栏暂时完成,下面去定义工具条

事实上NavigationController自带ToolBar,所以有更加方便的使用方法,使用自定义ToolBar可以是你有特殊需求,或者想自定样式(或者不知道自带ToolBar……)

先讲自定义的

我们可以新建一个View,父类选择UIToolBar,这就是我们自己的工具条View

ToolBar作为一个独立的View,和之前的代码布局中我们自己的Mainview没什么区别,想添加控件的方法都是一样的

只不过这个ToolBar只是一个工具栏,所以定位只在工具栏的一块小区域中定位,这是差不多唯一的不同

现在,我们要加载的有我们本身想要的一个View,通过改变rootController类型添加了导航栏,现在我们又要添加导航条,要加载的就不止一个View

在上次单纯的代码布局中,在Viewcontroller.m中重写的loadView是这样的

-(void)loadView
{
self.view = [[MainView alloc]initWithFrame:[UIScreen mainScreen].bounds];
}

直接把定义的根view赋值了我们自己的Mainview这一个,现在我们需要多个,就可以

-(void)loadView
{
[self.navigationItem setTitle:@"备忘录"];
[super loadView];
[self.view addSubview:[[NoteListView alloc]
initWithFrame:[UIScreen mainScreen].bounds
style:UITableViewStylePlain]];
[self.view addSubview:[[NoteListToolbar alloc]
initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height - 44, [UIScreen mainScreen].bounds.size.width, 44)]];
}

先调用父类的loadView , [super loadView],来保证我们有一个基本的View存在,虽然他是空的,表示为黑屏

接着可以向这个View中使用addSubview添加你想要的View

另外这里的self是最开始的rootController的类型UINavigationController,使用它的属性来定义了标题

然后是使用自带的ToolBar

在Viewcontroller中,可以使用self.navigationController.toolbar找到这个自带的ToolBar

//顺便一提,关于self,在Appdelegate中,使用的是

// UINavigationController *rootNav = [[UINavigationController alloc]

initWithRootViewController:[[ViewController alloc]init]];    来定义的window的rootcontroller

既然现在有了一个自带的ToolBar,我们只要把之前在我们自己的ToolBar文件中所添加的控件添加至这个自带的ToolBar即可

但是我们之前没发现它自带就是因为它默认是隐藏的……

在loadView中使用

[self.navigationController setToolbarHidden:NO];

来显示ToolBar

在loadView中,只要1、显示它 2、初始化它即可

可以在loadView函数下新增一个函数来专门放ToolBar的初始化

//toolbar
@property(strong , nonatomic)UILabel *LBNotecount;
@property(strong , nonatomic)UIButton *BTCreate; @end @implementation ViewController -(void)loadView
{
[self.navigationItem setTitle:@"导航栏"];
[super loadView];
_list =[[NoteListView alloc]initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
[self.view addSubview:_list]; // _toolbar = [[NoteListToolbar alloc]
// initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height - 44, [UIScreen mainScreen].bounds.size.width, 44)];
// [self.view addSubview: _toolbar];
// [_toolbar.BTCreate addTarget:self action:@selector(createPressed:)forControlEvents:UIControlEventTouchUpInside]; [self.navigationController setToolbarHidden:NO];
[self loadtoolbar:self.navigationController.toolbar];
//self.navigationController.toolbar; } -(void)loadtoolbar:(UIToolbar *)toolbar
{
_LBNotecount = [[UILabel alloc]
initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/2 - 60, toolbar.bounds.size.height/2 - 10, 120, 20)];
[_LBNotecount setText:@"工具栏"];
[_LBNotecount setTextAlignment:NSTextAlignmentCenter];
[toolbar addSubview:_LBNotecount]; _BTCreate = [[UIButton alloc]
initWithFrame:CGRectMake(0, 0, 20, 20)];
[_BTCreate setBackgroundColor:[UIColor greenColor]];
[toolbar addSubview:_BTCreate];
[_BTCreate addTarget:self action:@selector(createPressed:)forControlEvents:UIControlEventTouchUpInside]; }

SSH  git@github.com:kakinuma4ko/iOSDmo.git

iOS 导航栏 工具条的更多相关文章

  1. NavUtils【底部虚拟导航栏工具类】

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 获取底部虚拟导航栏的高度值 效果图 代码分析 checkDeviceHasNavigationBar(Context context ...

  2. iOS:导航栏的工具条和导航条

    功能:用NAV视图控制器打开新的视图,默认工具条和导航条隐藏,双击显示之 // // main.m // Hello // // Created by lishujun on 14-8-28. // ...

  3. ios隐藏导航栏底线条和导航、状态栏浙变色

    方法一遍历法: 在你需要隐藏的地方调用如下代码 [self findlineviw:self.navigationBar].hidden = YES; -(UIImageView*)findlinev ...

  4. iOS导航栏背景,标题和返回按钮文字颜色

    在iOS7下,默认导航栏背景,颜色是这样的,接下来我们就进行自定义,如果你仅仅是更改一下背景和颜色,代码会很简单,不需要很复杂的自定义View来替代leftBarItem 更改导航栏的背景和文字Col ...

  5. iOS 导航栏实现总结

    目标: 在UI界面中实现 整体效果的导航栏, 比如1 首页无导航条,次页有导航条, 2 导航条中不包含下方不包含黑边 3 导航条包含多个筛选项 等等 问题: 用系统带的NavigateBar 来实现时 ...

  6. IOS 导航栏属性设置

    IOS 7 以上系统导航栏: [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]]; // 返回按钮颜色 [UINaviga ...

  7. 【Swift】iOS导航栏错乱的原因

    #iOS开发高级技巧#导航栏错乱,也就是导航栏的显示效果与内容区不匹配,引发原因很多,其中最重要的有两个原因: 1.在viewwillappear,viewwilldisappear两个函数中,设置导 ...

  8. 转:ios导航栏设置

    原帖:http://www.cocoachina.com/industry/20131104/7287.html 本文提供的代码需要用Xcode 5来执行.如果你还在使用老版本的Xcode,那么在运行 ...

  9. iOS 导航栏黑线,UIImage 枚举处理方式

      ios 找出导航栏下面的黑线(可隐藏,改变样式等) http://www.jianshu.com/p/effa4a48f1e3     设置UIImage的渲染模式:UIImage.renderi ...

随机推荐

  1. linux 内存泄露检测工具

    Valgrind Memcheck 一个强大开源的程序检测工具 下载地址:http://valgrind.org/downloads/current.html Valgrind快速入门指南:http: ...

  2. regsvr32 bypass windows defender 新思路

    原文链接:blog 在对regsvr32的用法进行了解之后,对于Casey Smith的远程js脚本执行命令的思路很感兴趣. 命令语法如下: regsvr32 /s /n /u /i:http://1 ...

  3. 网站搭建-云服务器是什么-云服务器ECS是什么

    学习上瘾了,本博客关闭,后期再总结整理.

  4. 在实际开发中Java中enum的用法

    在日常项目的开发中,往往会存在一些固定的值,而且"数据集"中的元素是有限的. 例如:st_code// 一些状态机制:01-激活  02-未激活  03 -注册..等等 还有一特性 ...

  5. 多测师讲解pyhon__hashlib_高级讲师肖sir

    一.加密,加密成16进制的字符串 # import hashlib # 导入hashlib模块# md = hashlib.md5() # 获取一个md5加密算法对象# md.update('需要加密 ...

  6. MeteoInfoLab脚本示例:AIRS Swath HDF数据

    例子中的AIRS Swath HDF数据在Polar Stereographic(南极)投影中接近矩形,需要先从数据中读出经纬度及相关数据数组,利用surfacem函数绘制Swath数据(散点),在s ...

  7. MeteoInfoLab脚本示例:获取一维数据并绘图

    气象数据基本为多维数据(通常是4维,空间3维加时间维),只让数据中一维可变,其它维均固定即可提取一维数据.比如此例中固定了时间维.高度维.纬度维,只保留经度维可变:hgt = f['hgt'][0,[ ...

  8. C 和 C++ 打起来了!曾今最亲密的伙伴到现今的不爽?

    70年代初,贝尔实验室创建了C语言,它是开发UNIX的副产品.很快C就成为了最受欢迎的编程语言之一.但是对于Bjarne Stroustrup来说,C的表达能力还不够.于是,他在1983年的博士论文中 ...

  9. 自定义常用input表单元素一:纯css 实现自定义checkbox复选框

    最下面那个是之前写的  今天在做项目的时候发现,之前写的貌似还是有点多,起码增加的span标签可以去掉,这样保持和原生相同的结构最好的,仅仅是样式上的变化.今天把项目中的这个给更新上来.下面就直接还是 ...

  10. npm install 几种不同后缀安装模式的区别

    --save/--save --dev/nothing / -g 区别,及package.json基本目录结构介绍 https://www.jianshu.com/p/e10f981972ff