系统方式:

    //1.设置导航栏背景图片
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = [[UIImage alloc]init]; [[self navigationController] setNavigationBarHidden:NO animated:YES];
self.navigationController.navigationBar.backgroundColor = [[UIColor alloc] initWithRed:248/255.0 green:248/255.0 blue:248/255.0 alpha:1.0]; //2.导航面板左边的取消按钮
UIButton* cancelButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
if(cancelButton != nil)
{
[cancelButton setTitle:POST_CANCEL_BUTTON forState: UIControlStateNormal];
[cancelButton setFrame:CGRectMake(0, 0, WIDTH_SCREEN/5.0, 44)];
[cancelButton setTitleColor:[[UIColor alloc] initWithRed:0 green:158/255.0 blue:150/255.0 alpha:1.0]forState:UIControlStateNormal];
cancelButton.titleLabel.font = [UIFont systemFontOfSize: 16.0];
cancelButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[cancelButton addTarget:self action:@selector(cancelButtonEventTouchUpInside)
forControlEvents :UIControlEventTouchUpInside]; UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:cancelButton];
if(leftItem != nil)
{
self.navigationItem.leftBarButtonItem = leftItem;
}
} //3.导航面板右边的公布按钮
UIButton* postButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
if (postButton != nil)
{
[postButton setFrame:CGRectMake(0, 0, WIDTH_SCREEN/5.0, 44)];
[postButton setTitle:@"公布" forState:UIControlStateNormal];
[postButton setTitleColor:[[UIColor alloc] initWithRed:0 green:158/255.0 blue:150/255.0 alpha:1.0]forState:UIControlStateNormal];
postButton.titleLabel.font = [UIFont systemFontOfSize: 16.0];
postButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
[postButton addTarget:self action:@selector(postButtonEventTouchUpInside)
forControlEvents :UIControlEventTouchUpInside];
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:postButton];
if(rightItem != nil)
{
self.navigationItem.rightBarButtonItem = rightItem;
}
} //4.导航面板中部文字
UILabel* navigationLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 44)];
if (navigationLabel != nil)
{
[navigationLabel setTextColor:[UIColor blackColor]];
navigationLabel.text = POST_NAVIGATION_TITLE;
[navigationLabel setTextAlignment:NSTextAlignmentCenter];
navigationLabel.font = [UIFont systemFontOfSize:18.0];
self.navigationItem.titleView = navigationLabel;
} //5.导航以下的一条切割线
UIView* line = [[UIView alloc]initWithFrame:CGRectMake(0, 20 + 44,WIDTH_SCREEN, 1)];
if (line != nil)
{
line.backgroundColor = [[UIColor alloc] initWithRed:221/255.0 green:221/255.0 blue:221/255.0 alpha:1.0];
[self.view addSubview:line];
}

自己定义:

    //1.创建导航栏视图
UIView *navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH_SCREEN, 65)];
if (navView != nil)//当导航视图没有载入成功的时候推出该方法
{
//1.为导航视图设置背景
navView.backgroundColor = [UIColor colorWithRed:248 / 255.0 green:248 / 255.0 blue:248 / 255.0 alpha:1];
[[self navigationController] setNavigationBarHidden:YES animated:YES]; //2.导航面板左边的取消按钮
UIButton* leftButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
if (leftButton != nil)
{
leftButton.frame = CGRectMake(15, 20, 65, 44);
[leftButton setTitle:POST_CANCEL_BUTTON forState: UIControlStateNormal];
[leftButton setTitleColor:[[UIColor alloc] initWithRed:0 green:158/255.0 blue:150/255.0 alpha:1.0]forState:UIControlStateNormal];
leftButton.titleLabel.font = [UIFont systemFontOfSize: 16.0];
leftButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[leftButton addTarget:self action:@selector(cancelButtonEventTouchUpInside)
forControlEvents :UIControlEventTouchUpInside];
[navView addSubview:leftButton];
}
//3.导航面板右边的公布按钮
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
if (rightButton != nil)
{
[rightButton setFrame:CGRectMake(WIDTH_SCREEN - 80, 20, 65, 44)];
[rightButton setTitle:@"公布" forState:UIControlStateNormal];
[rightButton setTitleColor:[[UIColor alloc] initWithRed:0 green:158/255.0 blue:150/255.0 alpha:1.0]forState:UIControlStateNormal];
rightButton.titleLabel.font = [UIFont systemFontOfSize: 16.0];
rightButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
[rightButton addTarget:self action:@selector(postButtonEventTouchUpInside)
forControlEvents :UIControlEventTouchUpInside];
[navView addSubview:rightButton];
} //4.导航面板中部文字
UILabel* navTitle = [[UILabel alloc] initWithFrame:CGRectMake(80, 20, WIDTH_SCREEN - 80 - 80, 44)];
if (navTitle != nil)
{
[navTitle setTextColor:[UIColor blackColor]];
navTitle.text = POST_NAVIGATION_TITLE;
[navTitle setTextAlignment:NSTextAlignmentCenter];
navTitle.font = [UIFont systemFontOfSize:18.0];
[navView addSubview:navTitle];
} //5.在导航视图底加入切割线
UIView *navDividingLine = [[UIView alloc] init];
if (navDividingLine != nil)
{
navDividingLine.frame = CGRectMake(0, 20 + 44, WIDTH_SCREEN, 1);
navDividingLine.backgroundColor = [UIColor colorWithRed:221 / 255.0 green:221 / 255.0 blue:221 / 255.0 alpha:1];
[navView addSubview:navDividingLine];
} //6.往view添加导航栏
[self.view addSubview:navView];
}

ios 导航栏(自己定义和使用系统方式)的更多相关文章

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

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

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

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

  3. IOS 导航栏属性设置

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

  4. 转:ios导航栏设置

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

  5. iOS 导航栏实现总结

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

  6. IOS 导航栏

    系统状态栏改为白色:在Supporting Files文件的info.plist文件中添加 新的key,名字为View controller-based status bar appearance,并 ...

  7. 转载 iOS拦截导航栏返回按钮事件的正确方式

    原文链接:http://www.jianshu.com/p/25fd027916fa 当我们使用了系统的导航栏时,默认点击返回按钮是 pop 回上一个界面.但是在有时候,我们需要在点击导航栏的返回按钮 ...

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

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

  9. Ios导航栏返回到指定的页面

    在自己的项目实现中有这样的一个需求.一般情况下我们的导航栏返回按钮,是上个页面跳转过来,点击返回按钮返回到上来界面.但是在实际需求中有的并不是这么简单的.有的界面返回是只确定的界面.所以当时自己在实现 ...

随机推荐

  1. 1CSS简介

    -------------------------------------------------------------------------------------------------- - ...

  2. shell script练习:利用日期进行文件的创建

    随日期变化:利用 date 进行文件的创建 想像一个状况,假设我的服务器内有数据库,数据库每天的数据都不太一样,因此当我备份时, 希望将每天的数据都备份成不同的档名,这样才能够让旧的数据也能够保存下来 ...

  3. Java jre7及以上版本中的switch支持String的实现细节

    Java7中的switch支持String的实现细节 作者: zsxwing 更新: 2013-03-04 21:08:02 发布: 2012-04-26 13:58:19 在Java7之前,swit ...

  4. JS高级——歌曲管理

    1.将歌曲管理的CURD方法放到原型中 2.在构造函数中,我们只有一个属性是songList,因为音乐库不是共有的,如果将songList放入原型中,任何一个人的一次修改songList,都将把son ...

  5. jQuery——插件制作

    1.$.fn.extend:扩展 jQuery 元素集来提供新的方法(通常用来制作插件),使用时是$('选择器').方法 2.$.extend:扩展jQuery对象本身,用来在jQuery命名空间上增 ...

  6. C#连接Sqlite 出现:混合模式程序集是针对“v2.0.50727”版的运行时生成的,在没有配置其他信息的情况下,无法在 4.0 运行时中加载该程序集。的解决方案

    C#连接Sqlite 出现: 混合模式程序集是针对“v2.0.50727”版的运行时生成的,在没有配置其他信息的情况下,无法在 4.0 运行时中加载该程序集.的解决方案 C#连接sqlite数据库代码 ...

  7. 如何在Android Studio中查看一个类的继承关系呢?

    在面板顶部的工具栏中,找到Navigate,然后在下拉列表中,找到“Type Hierarchy”(快捷键 Ctrl+H),点击.即可在面板右侧出现该类的Hierarchy层级图.

  8. apk的包名修改

    今天,想在android手机上安装两个相同的应用,本以为可以安装不同版本的,试了几次,均相互覆盖了,于是,只能设法修改apk所对应的包名(package name). 目的声明:本文只是为了满足DIY ...

  9. js里的深度克隆

    ES6 数组克隆 let arr = [1,2,3,4,5]; let arr1 = [...a]; arr1 = ["a","b","c" ...

  10. mysql命令整理

    MySQL大小写通用. 一.常见用的mysql指令 1.show databases; #查看当前所有库 2.show tables; #查看所在库中的所有表 3.use 库名; #进入该库 4.sh ...