ios 导航栏(自己定义和使用系统方式)
系统方式:
//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 导航栏(自己定义和使用系统方式)的更多相关文章
- iOS 导航栏黑线,UIImage 枚举处理方式
ios 找出导航栏下面的黑线(可隐藏,改变样式等) http://www.jianshu.com/p/effa4a48f1e3 设置UIImage的渲染模式:UIImage.renderi ...
- iOS导航栏背景,标题和返回按钮文字颜色
在iOS7下,默认导航栏背景,颜色是这样的,接下来我们就进行自定义,如果你仅仅是更改一下背景和颜色,代码会很简单,不需要很复杂的自定义View来替代leftBarItem 更改导航栏的背景和文字Col ...
- IOS 导航栏属性设置
IOS 7 以上系统导航栏: [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]]; // 返回按钮颜色 [UINaviga ...
- 转:ios导航栏设置
原帖:http://www.cocoachina.com/industry/20131104/7287.html 本文提供的代码需要用Xcode 5来执行.如果你还在使用老版本的Xcode,那么在运行 ...
- iOS 导航栏实现总结
目标: 在UI界面中实现 整体效果的导航栏, 比如1 首页无导航条,次页有导航条, 2 导航条中不包含下方不包含黑边 3 导航条包含多个筛选项 等等 问题: 用系统带的NavigateBar 来实现时 ...
- IOS 导航栏
系统状态栏改为白色:在Supporting Files文件的info.plist文件中添加 新的key,名字为View controller-based status bar appearance,并 ...
- 转载 iOS拦截导航栏返回按钮事件的正确方式
原文链接:http://www.jianshu.com/p/25fd027916fa 当我们使用了系统的导航栏时,默认点击返回按钮是 pop 回上一个界面.但是在有时候,我们需要在点击导航栏的返回按钮 ...
- 【Swift】iOS导航栏错乱的原因
#iOS开发高级技巧#导航栏错乱,也就是导航栏的显示效果与内容区不匹配,引发原因很多,其中最重要的有两个原因: 1.在viewwillappear,viewwilldisappear两个函数中,设置导 ...
- Ios导航栏返回到指定的页面
在自己的项目实现中有这样的一个需求.一般情况下我们的导航栏返回按钮,是上个页面跳转过来,点击返回按钮返回到上来界面.但是在实际需求中有的并不是这么简单的.有的界面返回是只确定的界面.所以当时自己在实现 ...
随机推荐
- viewDidUnload,viewDidLoad,viewWillAppear,viewWillDisappear的作用以及区别
viewDidLoad:在视图加载后被调用 viewWillAppear:视图即将可见时调用.默认情况下不执行任何操作 viewDidAppear: 视图已完全过渡到屏幕上时调用 viewWillDi ...
- 关于onActivityResult方法不执行的问题汇总
我们不生产代码, 只是大自然的搬运工. 首先致谢: https://blog.csdn.net/sbvfhp/article/details/26858441 场景描述: 在A activity(由 ...
- CSS——font
行高的量取方式: 1.第一行可设置margin-top值.然后将第一文字顶部到第二行文字顶部的值作为行高的值(要注意对齐方式) 2.将 3.电视上 font:12px/1.5//字体12px,行高1. ...
- git使用原理
如果需要新建仓库: mkdir new_artcle//artcle为文件名 cd new_artcle//进入该目录 git init //初始化工作空间 git add 文件名(article) ...
- AcDbTable 类
Table 例子学习笔记在这个例子中,ARX向我们展示了ACDBTABLE类的一些基本操作方法,ACDBTABLE类是ACAD2005及其以后的产品,应该是说ACDBDATATABLE的升级产品,Ac ...
- Scrapy爬虫框架 基础
1< scrapy的安装 命令行安装 pip install scrapy <常见错误是缺少 wim32api 安装win32api pip install pywin32 <还有就 ...
- Nginx反向代理WebSocket(WSS)
1. WebSocket协议 WebSocket 协议提供了一种创建支持客户端和服务端实时双向通信Web应用程序的方法.作为HTML5规范的一部分,WebSockets简化了开发Web实时通信程序的难 ...
- time、datatime模块
python中时间日期格式化符号 %Y 年份(4位数表示) %y 年份(2位数表示) %m 月份(01-12) %d 月内中的一天(0-31) %H 24小时制小时数 %I 12小时制小时数 %M 分 ...
- Linux之网络文件共享服务(FTP)
一.FTP概念 •File Transfer Protocol 早期的三个应用级协议之一 •基于C/S结构 •双通道协议:数据和命令连接 •数据传输格式:二进制(默认)和文本 •两种模式:服务器角度 ...
- 利用WMITool解决浏览器快捷方式启动参数被篡改以及浏览器主页被劫持的问题
先说说症状 症状①:通过快捷方式启动浏览器,首页跳转到2345以及hao123网址导航页,切系统内安装的多款浏览器(IE.Chrome.Firefox.Opera.Safari.Maxthon)症状相 ...