zoukankan      html  css  js  c++  java
  • IOS7中修改导航栏的颜色

    设置导航栏的背景颜色

    在iOS 7中,不再使用tintColor属性来设置导航栏的颜色,而是使用barTintColor属性来修改背景色。我们可以在AppDelegate.m文件中的方法didFinishLaunchingWithOptions:里面添加如下代码来修改颜色:

    1. [[UINavigationBar appearance] setBarTintColor:[UIColor yellowColor]]; 

    效果如下图所示:

    一般情况,我们都会使用自己的颜色,下面这个宏用来设置RGB颜色非常方便:

    1. #define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0] 

    将上面这个宏放到AppDelegate.m文件中,然后通过这个宏来创建一个UIColor对象(根据指定的RGB)。如下示例:

    1. [[UINavigationBar appearance] setBarTintColor:UIColorFromRGB(0x067AB5)]; 

    默认情况下,导航栏的translucent属性为YES。另外,系统还会对所有的导航栏做模糊处理,这样可以让iOS 7中导航栏的颜色更加饱和。如下图,是translucent值为NO和YES的对比效果:

    要想禁用translucent属性,可以在Storyboard中选中导航栏,然后在Attribute Inspectors中,取消translucent的勾选。

  • 相关阅读:
    VM 下增加磁盘空间
    在APACHE服务器上的访问方式上去除index.php
    1
    数组累加兼eval性能测试
    webstorm软件使用记录
    gulp配置安装使用
    jQuery方法笔记
    搭建Grunt集成环境开发SASS
    msysgit使用方法
    十诫在天主教和新教之间的差别
  • 原文地址:https://www.cnblogs.com/liuxp1990/p/3485241.html
Copyright © 2011-2022 走看看