iOS设置导航栏透明度
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:
E.g. in your ..AppDelegate.m add these lines in didFinishLaunchingWithOptions
//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:
//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):
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设置导航栏透明度的更多相关文章
- IOS 设置导航栏
//设置导航栏的标题 self.navigationItem setTitle:@"我的标题"; //设置导航条标题属性:字体大小/字体颜色…… /*设置头的属性:setTitle ...
- IOS 设置导航栏全局样式
// 1.设置导航栏背景 UINavigationBar *bar = [UINavigationBar appearance]; [bar setBackgroundImage:[UIImage r ...
- iOS 设置导航栏之二(设置导航栏的颜色、文字的颜色、左边按钮的文字及颜色)
#import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicati ...
- iOS 设置导航栏的颜色和导航栏上文字的颜色
#import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @pr ...
- iOS设置导航栏样式(UINavigationController)
//设置导航栏baritem和返回baiitem样式 UIBarButtonItem *barItem = [UIBarButtonItem appearance]; //去掉返回按钮上的字 [bar ...
- iOS 设置导航栏全透明
- (void)viewWillAppear:(BOOL)animated{ //设置导航栏背景图片为一个空的image,这样就透明了 [self.navigationController.navig ...
- ios 设置导航栏背景色
//设置导航栏背景色 如果上面的不好用 就用下面的 [self.navigationController.navigationBar setBackgroundImage:[UIImage image ...
- IOS设置导航栏字体大小及颜色
方法一: 自定义视图,定义一个lable,相关属性在lable里设置 核心方法: self.navigationItem.titleView = titleLabel; 方法二:用系统方法直接设置 [ ...
- iOS设置导航栏标题
方法一:在UIViewController中设置self.title. 方法二:设置self.navigationItem.titleView.
随机推荐
- golang中使用mongodb的操作类以及如何封装
mgo简介 mongodb官方没有关于go的mongodb的驱动,因此只能使用第三方驱动,mgo就是使用最多的一种. mgo(音mango)是MongoDB的Go语言驱动,它用基于Go语法的简单API ...
- Android 4.4KitKat AudioFlinger 流程分析
AudioFlinger(AF)是一个服务,具体的启动代码在av\media\mediaserver\Main_mediaserver.cpp中: int main(int argc, char** ...
- Android简单介绍
1)Android定义: 2)版本号变迁 3)开发类型 4)Android五大组件 5)Android五大布局
- mysql init_connect
init_connect 服务器为每个连接的客户端执行的字符串.字符串由一个或多个SQL语句组成.要想指定多个语句,用分号间隔开.例如,每个客户端开始时默认启用autocommit模式.没有全局服务器 ...
- linux下的ssh与ssh客户端
经常会看到ssh客户端,或者听到ssh到某台机器..问题:ssh和ssh客户端什么关系? 1.ssh,secure shell,是一种网络交互协议,也指实现该协议的网络服务程序.主要用于远程机器管理, ...
- 音频采样中left-or right-justified(左对齐,右对齐), I2S时钟关系
音频采样中left-or right-justified(左对齐,右对齐), I2S时钟关系 原创 2014年02月11日 13:56:51 4951 0 0 刚刚过完春节,受假期综合症影响脑袋有点发 ...
- 二次开发第N天。。。。。。。。自动分页问题
phpcms\modules\content\fields\pages\form.inc.php 注意修改时,如果是gbk版本可以直接用记事本修改保存!如果是utf8 要用工具修改,或者保存的时候要记 ...
- python之版本管理
linux 环境下怎样对不同的python环境进行 方便的切换呢?update-alternatives工具能够非常方便的帮我们完成这个任务.而windows环境下可通过anaconda来完成. 1. ...
- linux系统的开机引导、启动流程
固件(CMOS/BIOS) > POST 加电自检 ↓ 自举程序(GRUB)> 加载内核 ↓ 载入内核 > 驱动硬件 ↓ 启动进程 init ↓ 读取执行配置文件/etc/initt ...
- Tomcat下配置多个Project的虚拟主机
server.xml中,添加<Context path="/project2" docBase="D:\MyProjects\project2\WebContent ...