系统方式:

    //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. MVC系列学习(八)-分布视图

    1.本次学习实例 1.1.建议:为了尽可能让项目简单,就新建一个空的mvc项目,同时添加任何视图不用模板页 1.2注意:在添加LoginPart的分部视图时,要记得沟一个沟 2.项目代码,如下 总共三 ...

  2. JS——回调函数

    1.回调函数作为参数的形式进行使用 2.回调函数一定程度上达到了解耦效果(模块化.功能化) <script> console.log(op(1, 2, add)); console.log ...

  3. [Windows Server 2008] 安装IIS7.5及FTP

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:安装IISII ...

  4. [Windows Server 2012] 安装PHP+MySQL方法

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:PHP+MyS ...

  5. Java_Web三大框架之Hibernate+jsp+selvect+HQL查询数据

    俗话说:"好记性不如烂笔头".本人学习Hibernate也有一个星期了,对Hibernate也有一个初步的了解.下面对Hibernate显示数据做个笔记,使用租房系统的Hibern ...

  6. Git与SVN版本控制系统

    关于版本控制 什么是版本控制?版本控制是一种记录一个或若干文件内容变化,以便将来查阅特定版本修订情况的系统.在本书所展示的例子中,我们仅对保存着软件源代码的文本文件作版本控制管理,但实际上,你可以对任 ...

  7. HDU_1848_博弈,sg函数

    Fibonacci again and again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

  8. C# Winform 最大化后 任务栏还显示解决

    //最大化 this.WindowState = FormWindowState.Maximized; //窗体最大化时 非全屏 不会遮盖任务栏 //去掉标题栏 this.FormBorderStyl ...

  9. zoom,zoom与haslayout的关系,zoom与transform: scale( )的区别

    1.zoom:(缩放)

  10. 为什么阿里规约手册要求谨慎使用Arrays.asList方法

    前言 在开发中,有时候会碰到把多个参数,或者说把数组转成List的需求,通常我们会使用 Arrays.asList()方法.但是该方法在使用的过程中,稍有不慎就会出现严重的异常.有如下代码: @Tes ...