美文网首页
iOS导航栏隐藏的情况下设置状态栏为黑色

iOS导航栏隐藏的情况下设置状态栏为黑色

作者: 阿拉斯加的狗 | 来源:发表于2020-03-24 12:02 被阅读0次

第一种方法

// 导航栏变为透明

[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];

相关文章

网友评论

      本文标题:iOS导航栏隐藏的情况下设置状态栏为黑色

      本文链接:https://www.haomeiwen.com/subject/iukoyhtx.html