系统方式:

    //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导航栏使用总结

    点击上方"程序员大咖",选择"置顶公众号" 关键时刻,第一时间送达! 作者:风恣 文:https://www.jianshu.com/p/50cd38f2772 ...

  2. iOS 导航栏隐藏和显示

    1: 导航栏隐藏.显示之间跳转 iOS 导航栏对于隐藏造成的动画 可以通过在 viewWillAppear 和 viewWillDisappear 来设置完成 - (void)viewWillAppe ...

  3. ios15从隐藏系统导航栏页面进入显示系统导航栏页面后,期望系统导航栏背景色为白色,但是导航栏背景变成黑色问题

    ios15从隐藏系统导航栏页面进入显示系统导航栏页面后,期望系统导航栏背景色为白色,但是导航栏背景变成黑色问题. 经过多次分析是因为底层大背景被设置了默认颜色引起,把它设置成对应白色就可以了: sel ...

  4. 自定义iOS导航栏背景,标题和返回按钮文字颜色-----转载自gyz413977349

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

  5. iOS导航栏遮挡问题的总结

    一.背景:在做开发的时候经常不经意就出现导航栏遮挡主视图的情况,之前出现这种情况我会先看看View UI Hierarchy,然后把视图的坐标手动调整,例如把视图的y坐标写成64(建议封装成宏,因为有 ...

  6. iOS 导航栏实现总结

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

  7. iOS 导航栏遮挡问题 --- iOS开发系列 ---项目中成长的知识七

    不知大家有没有遇见过自己写的tableview被导航栏遮挡住的问题,反正我是遇见过! 因为在ios7以后所有的UIViewController创建后默认就是full Screen的,因此如果带导航栏的 ...

  8. iOS导航栏标题错乱的解决方法

    一般隐藏和显示导航栏,只要在基类如下写就好: -(BOOL)needHiddenNavigationBar:(UIViewController *)vc{BOOL isHidden = NO;if ( ...

  9. iOS 导航栏遮挡视图

    导航栏遮盖视图 iOS7 之前: UINavigationBar 的 translucent 属性默认 NO. (导航栏默认完全不透明) iOS7 之后: UINavigationBar 的 tran ...

最新文章

  1. linux虚拟机网络设置(本机使用公司内网)
  2. mdkstc系列器件支持包下载_WPS Office 2019 For Linux(2020/10/21)更新-支持PDF编辑
  3. 国产与第三方库FFmpeg SDK
  4. 分布式架构的前世今生...
  5. uoj#351. 新年的叶子(概率期望)
  6. docker nacos mysql nginx 集群一台
  7. 已知段地址,求CPU寻址范围
  8. oracle blob update,Oracle数据库中对BLOB数据的操作问题
  9. C# CLRInsideOut 托管代码与非托管代码互操作,产生相关调用代码的好工具 C++ 头文件转C# 的好工具...
  10. I00033 消除游戏
  11. objective-c 中的关联介绍
  12. 员工提出离职时,再挽留已经迟了
  13. lammps教程:group命令详解
  14. 主机甲和乙已建立了 TCP 连接,甲始终以 MSS=1KB 大小的段发送数据,并一直有数据 发送;乙每收到一个数据段都会发出一个接收窗口为 10KB 的确认段。若甲在 t 时刻发生超 时时拥塞窗口为
  15. 单射、满射、双射(一一映射)
  16. 黑马程序员——结缘黑马
  17. IE不能上网浏览的问题
  18. bind9 dlz mysql_源码安装Bind 9.10 正式版 开启DLZ数据库支持 和 数据库view查询
  19. 邮件发送失败服务器繁忙,★邮件发送失败的原因和解决方法
  20. 计算机原理接口,《计算机原理与接口》教学大纲

热门文章

  1. Java中input与output_java中的Io(input与output)操作总结(四)
  2. 频段表_VoLTE高低频段覆盖能力研究
  3. Ubuntu下 Hadoop 1.2.1 配置安装
  4. TCP协议连接过程详解
  5. java中堆栈(stack)和堆(heap)
  6. 为什么晚上咳嗽很厉害
  7. Hibernate 批量插入、更新与删除
  8. Serializable的作用
  9. ywy_c_asm题
  10. Python入门学习笔记11(静态方法、类方法与属性方法)