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

来源:互联网 发布:linux内核入门书籍 编辑:程序博客网 时间:2024/06/11 19:48

设置透明的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
1 0