zoukankan      html  css  js  c++  java
  • iOS开发之--最简单的导航按钮更换方法/导航颜色的改变

    有很多时候,我们需要用到导航,那么更换导航的时候,是在那用那修改,还是自定义一个导航,或者是声明一个代理方法,经过查资料和对导航属性的一些了解,用一种方法最为简单,就是在入口类里面添加一个方法,调用偏移量的方法,达到隐藏默认导航按钮的效果,代码如下:

    - (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 = - 500; offset.vertical = - 500; [buttonItem setBackButtonTitlePositionAdjustment:offset forBarMetrics:UIBarMetricsDefault]; }

    这样就可以了,每个页面的返回按钮都会被替换掉,效果如下:

  • 相关阅读:
    linux command line send email
    js的小随笔
    JavaScript的严格模式
    nodejs学习笔记<六>文件处理
    nodejs学习笔记<五>npm使用
    nodejs学习笔记<四>处理请求参数
    nodejs学习笔记<三>关于路由(url)
    nodejs学习笔记<一>安装及环境搭建
    转:HTTP 301 跳转和302跳转的区别
    前端代码新写法——Zen Coding
  • 原文地址:https://www.cnblogs.com/hero11223/p/6046956.html
Copyright © 2011-2022 走看看