系统方式:

    //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. Mac上随时切换PYTHON版本

    在MAC上,默认安装了python2.*,自己又安装了python3.*:假如我们需要在终端上随时切换python控制台到需要的版本,可以采用下面的方法. 1.用命令   sudo vi ~/.bas ...

  2. C++ 由虚基类 虚继承 虚函数 到 虚函数表

    //虚基类:一个类可以在一个类族中既被用作虚基类,也被用作非虚基类. class Base1{ public: Base1(){cout<<"Construct Base1!&q ...

  3. 336 Palindrome Pairs 回文对

    给定一组独特的单词, 找出在给定列表中不同 的索引对(i, j),使得关联的两个单词,例如:words[i] + words[j]形成回文.示例 1:给定 words = ["bat&quo ...

  4. [转]Linux finger命令

    转自:http://os.51cto.com/art/201003/186354.htm Linux finger命令是系统管理员的必备命令之一,他可以清楚的告诉管理员有多少用户在同时使用他所管理的L ...

  5. 3 工欲善其事必先利其器,C#开发环境准备

    1.       为什么选择C#作为入门的编程语言开始学习? Java和C#是比较主流的两大开发语言.(除了这两种还有什么比较流行的开发语言?)相对于Java,C#的入门要容易一些.学习java开发需 ...

  6. 对“空引用”说bye-bye

    大家可能经常遇到这种情况:当一个对象为null时,调用这个对象的方法或者属性时,就会报错:“Object reference not set to an instance of an object.” ...

  7. bootstrap图标乱码问题-解决方案

    楼主在使用bootstrap时,出现了图标乱码问题,经过多次查找,才解决了问题(最后发现真的是很好解决的问题(^^)) 如果出现乱码 请直接在自己写的CSS中重新引入一下font文件中的字体就好了 @ ...

  8. JS——dom

    节点的获取 <script> var div = document.getElementById("box");//返回指定标签 var div = document. ...

  9. 【sqli-labs】 less58 GET -Challenge -Double Query -5 queries allowed -Variation1 (GET型 挑战 双查询 只允许5次查询 变化1)

    单引号闭合成功,但是union select结果不对 http://192.168.136.128/sqli-labs-master/Less-58/?id=0' union select 1,2,3 ...

  10. CAD类型转换

    AcDbEntity *pEnt; AcDbCircle *pcir = AcDbCircle::cast(pEnt); static_cast<AcDbCircle*>(pEnt); p ...