您的位置:首页 > 编程语言 > VB

设置透明的NavBar 获取纯色图片

2015-12-06 10:44 615 查看

设置透明的NavBar 获取纯色图片

import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor cyanColor];

////获取纯色图片的方法
UIImage *image = [self imageWithColor:[[UIColor blackColor] colorWithAlphaComponent:0.15]];
////设置NavBar的背景图片
[self.navigationController.navigationBar setBackgroundImage:image
forBarMetrics:UIBarMetricsDefault];
////去除阴影分割线的方法
[self.navigationController.navigationBar setShadowImage:image];
self.navigationController.navigationBar.translucent = YES;
}

////获取一个纯色的图片
- (UIImage *)imageWithColor:(UIColor*)color {
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  NavBar