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.
随机推荐
- DEV 第三方控件报表分类汇总
最近这段时间难得空闲,于是打算做个报表功能,主要实现数据的分类汇总,以便不时之需.首先看看效果: 主要是根据工程类型这个字段进行分类,每个分类下对应的项目金额进行求和,当然,你也可以根据实际需求,进行 ...
- 在需要隐藏navigationController控制器
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.navigationControll ...
- REP-20147 Cannot implement column link for this detail SQL query. Converting to group link.
注:本文为原创,作为学习交流使用,转载请标明作者及出处,作者保留追究法律责任的权力. Lumen Su lzsu1989#gmail.com (#=@) www.cnblogs.com/lzsu198 ...
- js 判断是否为mac电脑 、还是windows操作系统
/** * 是否为mac系统(包含iphone手机) * */ var isMac = function() { return /macintosh|mac os x/i.test(navigator ...
- 关于Unity实现游戏录制功能的思考
录制无非两种做法,录制操作和录制行为. 录制操作要考虑到随机行为,但其实也可以两者混合.如果随机行为过多,并且随机行为无法用种子复现,可以完全用录制的方式 最后再统一压缩 这里yy的就是录制行为的做法 ...
- Atitit.判断汉字的编码 regedit 注册表里面的reg_sz
Atitit.判断汉字的编码 regedit 注册表里面的reg_sz 1. 可以判断出是unicode编码1 2. 有下面分割ucs2 大头小偷编码1 3. 使用小偷编码测试1 4. 注册表里面的r ...
- XSS绕过与防御总结
跨站脚本攻击(Cross Site Scripting),为不和层叠样式表(Cascading Style Sheets, CSS)的缩写混淆,故将跨站脚本攻击缩写为XSS.恶意攻击者往Web页面里插 ...
- Android CoordinatorLayout 入门介绍
Android CoordinatorLayout 入门介绍 CoordinatorLayout View 知道如何表现 在 2015 年的 I/O 开发者大会上,Google 介绍了一个新的 And ...
- linux设置时间的方法
0. date -R 中国上海的时区是+8000 1.tzselect 设置时区,依次选择5,9,1,1(如果时区不一样,执行下面的命令得到之后时间是不一样的) 2.sudo ntpdate asi ...
- NGUI3.7.4实现循环拖动
前段时间下了NGUI新版本3.7.4,看到例子Endless Scroll Views,实现了循环拖动,可能会用到,先把实现步骤贴出来跟大家分享一下. 1.首先新建一个背景. 2.添加所需控件,类似滑 ...