As I support Colin's answer, I want to give you an additional hint to customize the appearance of an UINavigationBar including the alpha.

The trick is to use UIAppearance for your NavigationBar. This enables you to assign an UIImage to your NavigationBar's backgroundImage. You can generate these UIImages programmatically and use for that UIColors and set the colors' alpha properties as you want. I've done this in one of my own applications and it works as expected.

Here I give you some code snippets:

  1. E.g. in your ..AppDelegate.m add these lines in didFinishLaunchingWithOptions

  2. //create background images for the navigation bar
    UIImage *gradientImage44 = nil; //replace "nil" with your method to programmatically create a UIImage object with transparent colors for portrait orientation
    UIImage *gradientImage32 = nil; //replace "nil" with your method to programmatically create a UIImage object with transparent colors for landscape orientation //customize the appearance of UINavigationBar
    [[UINavigationBar appearance] setBackgroundImage:gradientImage44 forBarMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setBackgroundImage:gradientImage32 forBarMetrics:UIBarMetricsLandscapePhone];
    [[UINavigationBar appearance] setBarStyle:UIBarStyleDefault];

    2.Implement convenience methods to programmatically creates UIImage objects, e.g. create a new category for UIImage:

  3. //UIImage+initWithColor.h
    //
    #import <UIKit/UIKit.h> @interface UIImage (initWithColor) //programmatically create an UIImage with 1 pixel of a given color
    + (UIImage *)imageWithColor:(UIColor *)color; //implement additional methods here to create images with gradients etc.
    //[..] @end //UIImage+initWithColor.m
    //
    #import "UIImage+initWithColor.h"
    #import <QuartzCore/QuartzCore.h> @implementation UIImage (initWithColor) + (UIImage *)imageWithColor:(UIColor *)color
    {
    CGRect rect = CGRectMake(, , , ); // create a 1 by 1 pixel context
    UIGraphicsBeginImageContextWithOptions(rect.size, NO, );
    [color setFill];
    UIRectFill(rect); UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext(); return image;
    }

    3.Re-work your image creation in 1. (#import "UIImage+initWithColor.h" in AppDelegate.m and replace the "nil"s):

  4. UIImage *gradientImage44 = [UIImage imageWithColor:[UIColor colorWithRed:1.0 green:0.0 blue:1.0 alpha:0.2]];
    UIImage *gradientImage32 = [UIImage imageWithColor:[UIColor colorWithRed:1.0 green:0.0 blue:1.0 alpha:0.2]];

    // 用图片当作背景 设置透明度

iOS设置导航栏透明度的更多相关文章

  1. IOS 设置导航栏

    //设置导航栏的标题 self.navigationItem setTitle:@"我的标题"; //设置导航条标题属性:字体大小/字体颜色…… /*设置头的属性:setTitle ...

  2. IOS 设置导航栏全局样式

    // 1.设置导航栏背景 UINavigationBar *bar = [UINavigationBar appearance]; [bar setBackgroundImage:[UIImage r ...

  3. iOS 设置导航栏之二(设置导航栏的颜色、文字的颜色、左边按钮的文字及颜色)

                      #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicati ...

  4. iOS 设置导航栏的颜色和导航栏上文字的颜色

    #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @pr ...

  5. iOS设置导航栏样式(UINavigationController)

    //设置导航栏baritem和返回baiitem样式 UIBarButtonItem *barItem = [UIBarButtonItem appearance]; //去掉返回按钮上的字 [bar ...

  6. iOS 设置导航栏全透明

    - (void)viewWillAppear:(BOOL)animated{ //设置导航栏背景图片为一个空的image,这样就透明了 [self.navigationController.navig ...

  7. ios 设置导航栏背景色

    //设置导航栏背景色 如果上面的不好用 就用下面的 [self.navigationController.navigationBar setBackgroundImage:[UIImage image ...

  8. IOS设置导航栏字体大小及颜色

    方法一: 自定义视图,定义一个lable,相关属性在lable里设置 核心方法: self.navigationItem.titleView = titleLabel; 方法二:用系统方法直接设置 [ ...

  9. iOS设置导航栏标题

    方法一:在UIViewController中设置self.title. 方法二:设置self.navigationItem.titleView.

随机推荐

  1. Bootstrap学习 进度条

    本文将介绍Bootstrap进度条,在本文中你将看到如何使用Bootstrap创建加载,重定向或动作状态的进度条 bootstrap进度条使用CSS3过渡和动画来获得该效果.Internet Expl ...

  2. jedis连接集群

    /**        * 集群版        */       @Test       public  void JedisJiuQun()       {           HashSet< ...

  3. 转: Tsung:开源多协议分布式负载&压力测试工具

    Main features High Performance: the load can be distributed on a cluster of client machines Multi-pr ...

  4. mqtt选择

    1.名称 MQTT kafka 2.历史 IBM推出的一种针对移动终端设备的发布/预订协议. LinkedIn公司开发的分布式发布-订阅消息系统.后来,成为Apache项目的一部分. 3.原理 基于二 ...

  5. (MVC)从客户端中检测到有潜在危险的 Request.Form 值

    在传统的.net Request验证中 ,只需要在WebConfig HttpRuntime节点 加入 RequestValidateMode 属性,值为2.0(此处2.0并非Framework版本) ...

  6. tcp_recvmsg 函数具体解释

    看了非常多网上关于tcp_recvmsg的文章,感觉解释的不太到位,或者非常多都是空口说白话,昨天分析了一下午tcp_recvmsg.感觉了解了十之八九,如今贴出来和大家分享一下. 须要背景:了解tc ...

  7. Python处理验证码第一篇(pytesser初探及报错处理)

    (原文链接:http://blog.csdn.net/Bone_ACE/article/details/50436587) 前言: 春节期间,无法全身心投入地去写爬虫,那就玩玩验证码吧,应该比较有趣! ...

  8. django源码分析----Related继承结构

    在django中关联关系大概可以分成many-to-one(foriegnkey).one-to-one.many-to-many 这三种.它们有如下的类结构 class RelatedField(F ...

  9. 点滴积累【other】---.net程序员面试题总结

    自己总结的.net的面试题. 说明:以下代码均已经过验证正确无误! C#: 1.c#实现N的阶乘: class Program { static void Main(string[] args) { ...

  10. CCNA2.0笔记_OSPF v2

    OSPF(开放最短路径优先)协议概述: - 链路状态路由协议 - 无类路由协议 - 要点:RouterID.区域ID - 触发更新 .以传播 LSA 代替路由表更新 - 快速响应变更(比距离矢量路由协 ...