NavigationBar全透明的实现

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

效果对比

实现前:
这里写图片描述

实现后:
这里写图片描述


实现代码

 //navigationbar全透明
    self.navigationController.navigationBar.translucent = YES;
    UIColor *color = [UIColor clearColor];
    CGRect rect = CGRectMake(0, 0, ZFScreenW, 64);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
    //self.navigationController.navigationBar.clipsToBounds = YES;

    //下面那条横线
    CGRect barF = CGRectMake(0, CGRectGetMaxY(rect), ZFScreenW, 1);
    UIView *bar = [[UIView alloc] initWithFrame:barF];
    bar.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:bar];

猜你喜欢

转载自blog.csdn.net/Feng512275/article/details/79339623