iOS UINavigationController导航条背景透明

来源:互联网 发布:java环境变量配置失败 编辑:程序博客网 时间:2024/05/06 17:11

//方法一

- (void)setCleanNavtion {

    //自定义背景

    [self.navigationController.navigationBarsetBackgroundImage:[UIImagenewforBarMetrics: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;

}




0 0
原创粉丝点击