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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_28125515/article/details/50193475

设置透明的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
阅读更多
换一批

没有更多推荐了,返回首页