iOS开发之--最简单的导航按钮更换方法/导航颜色的改变
2024-08-27 15:45:32
有很多时候,我们需要用到导航,那么更换导航的时候,是在那用那修改,还是自定义一个导航,或者是声明一个代理方法,经过查资料和对导航属性的一些了解,用一种方法最为简单,就是在入口类里面添加一个方法,调用偏移量的方法,达到隐藏默认导航按钮的效果,代码如下:
- (void)setNaviBack{
UIFont *font = [UIFont systemFontOfSize:16.f];
//title的颜色和字体大小
NSDictionary *textAttributes = @{
NSFontAttributeName : font,
NSForegroundColorAttributeName : [UIColor whiteColor]
};
UINavigationBar * navigationBar = [UINavigationBar appearance];
navigationBar.titleTextAttributes = textAttributes;
//导航栏的背景颜色
navigationBar.barTintColor = MainColor; //返回按钮的箭头颜色 [navigationBar setTintColor:[UIColor colorWithRed:0.984 green:0.000 blue:0.235 alpha:1.000]]; //设置返回样式图片 UIImage *image = [UIImage imageNamed:@"返回"]; image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; navigationBar.backIndicatorImage = image; navigationBar.backIndicatorTransitionMaskImage = image; UIBarButtonItem *buttonItem = [UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil]; //设置图片与文本的偏移量
UIOffset offset; offset.horizontal = - ; offset.vertical = - ; [buttonItem setBackButtonTitlePositionAdjustment:offset forBarMetrics:UIBarMetricsDefault]; }
这样就可以了,每个页面的返回按钮都会被替换掉,效果如下:
最新文章
- 如何在ubuntu里面关掉后台的meteor
- html5的发展历程和由此引起的政治斗争
- bootstrap之消息提示
- Android之下拉刷新,上啦加载的实现(一)
- Poj 1054 The Troublesome Frog / OpenJudge 2812 恼人的青蛙
- Bzoj 1901: Zju2112 Dynamic Rankings 树套树,线段树,平衡树,Treap
- Eclipse Maven Project
- System.AccessViolationException: 尝试读取或写入受保护的内存 解决办法
- jq 22 一个很好图片显示
- Flask-WTF 配置、验证及日志P4
- parted分区和挂载及非交互式操作
- 使用 nodeJs 开发微信公众号(设置自动回复消息)
- skynet记录7:第一个服务logger和第二个服务bootstrap
- spring profile
- intellij error updating changes svn解决办法
- java并发基础
- from __future__ import print_function的作用
- Effective C++ 随笔(1)
- ELK学习笔记之ELK架构与介绍
- deepin下安装python的Tkinter库
热门文章
- NowCoderG:最大平方数
- NPOI workbook.RemoveSheetAt(0); 删除sheet页 次序 sheettmpRequire.CopySheet(";Require";, true);
- WEP无线网络密码破解
- Lintcode---翻转二叉树
- Vim-复制选中内容至系统剪贴板,光标移动到指定行的行首和行尾
- removeFromParentAndCleanup和callfuncN_selector
- yii2中的资源....
- 工作流Activiti的学习总结(十二) activiti官方十分钟快速学习 (zhuan)
- 【转】在MAC下配置MySQL 5.7 数据库的编码问题
- inline函数出现 undefined reference 错误