iOS UINavigationController导航条背景透明

哈涵容
2023-12-01


//方法一


- (void)setCleanNavtion {


    //自定义背景

    [self.navigationController.navigationBarsetBackgroundImage:[UIImagenew] forBarMetrics:UIBarMetricsDefault];

    //消除阴影

   self.navigationController.navigationBar.shadowImage = [UIImage new];

}


//方法二

- (void)setNavtion {

    self.navigationController.navigationBar.translucent=YES;

    UIColor *color=[UIColorclearColor];

    CGRect rect =CGRectMake(0,0,self.view.frame.size.width,64);

    UIGraphicsBeginImageContext(rect.size);

    CGContextRef context =UIGraphicsGetCurrentContext();

    CGContextSetFillColorWithColor(context, [colorCGColor]);

    CGContextFillRect(context, rect);

    UIImage *image =UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    [self.navigationController.navigationBarsetBackgroundImage:imageforBarMetrics:(UIBarMetricsDefault)];

    self.navigationController.navigationBar.clipsToBounds=YES;

}






 

 类似资料: