iOS 设置导航栏和状态栏为透明黑色


第一种方法:

//    导航栏变为透明
[self.navigationController.navigationBar setBackgroundImage:[self ImageWithColor:[[UIColor blackColor]colorWithAlphaComponent:0.4]] forBarMetrics:0]; 
// 让黑线消失的方法 
self.navigationController.navigationBar.shadowImage=[UIImage new];

    //设置了setBackgroundImage,再设置barTintColor不起作用

//    self.navigationController.navigationBar.barTintColor = [[UIColor blackColor]colorWithAlphaComponent:0.4];

 

//将color转换成image方法

- (UIImage *)ImageWithColor:(UIColor *)backgroundColor {

    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);

    UIGraphicsBeginImageContext(rect.size);

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetFillColorWithColor(context, backgroundColor.CGColor);

    CGContextFillRect(context, rect);

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return image;

}

第二种方法:

    UIView *bg = [[UIView alloc]initWithFrame:CGRectMake(0, -20, KScreenWidth, kNavHeight)];
    bg.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.4];
    bg.userInteractionEnabled = YES;
    [self.navigationController.navigationBar addSubview:bg];
    [self.navigationController.navigationBar sendSubviewToBack:bg];

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM