系统方式:

    //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. 316 Remove Duplicate Letters 去除重复字母

    给定一个仅包含小写字母的字符串,去除重复的字母使得所有字母出现且仅出现一次.你必须保证返回结果是所有可能结果中的以字典排序的最短结果.例如:给定 "bcabc"返回 "a ...

  2. 【转】Linux下变量内容删除与替换

    转自:http://www.linuxidc.com/Linux/2015-01/111781.htm 当一个变量被赋予值后,有时会对变量的值进行一些微小的调整,比如删除变量值中特定一部份,或替换掉一 ...

  3. Android视频截图

    本文介绍如何获取视频中某个时间点的数据 调用以下方法即可,特别注意,在获取图片时的参数单位为微秒,不是毫秒 如果错用了毫秒会一直获取第一帧的画面 /** * 获取某个时间点的帧图片 * * @para ...

  4. 图解TCP/IP笔记(1)——TCP/IP协议群

    转载请注明:https://www.cnblogs.com/igoslly/p/9167916.html TCP/IP制定  制定:IETF 记录:RFC - Request for comment ...

  5. TCP简要讲解

    TCP被称为面向连接.面向流,可靠的传输层协议.它与UDP最大的不同在于它是可靠性的,所以需要可靠传输的时候就需要用到TCP,如果需要快速传输则选择UDP. TCP的连接又称为3次握手.   1).客 ...

  6. STL之string篇

    常用代码整理: #include<iostream> #include<cstdio> #include<cstring> #include<string&g ...

  7. sql中表变量

    今天在公司看sql优化的文章的时候,提到了表变量,做下笔记. 表变量 顺便复习下临时表.

  8. java攻城狮之路--复习JDBC(数据库连接池 : C3P0、DBCP)

    复习数据库连接池 : C3P0.DBCP 1.数据库连接池技术的优点: •资源重用:      由于数据库连接得以重用,避免了频繁创建,释放连接引起的大量性能开销.在减少系统消耗的基础上,另一方面也增 ...

  9. Ubuntu下获取内核源码

    查看当前系统使用的内核版本: apt-cache search linux-source 输出如下: linux-source - Linux kernel source with Ubuntu pa ...

  10. HDU_1068_Girls and Boys_二分图匹配

    Girls and Boys Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...