您的位置:首页 > 移动开发 > IOS开发

ios 导航栏透明

2016-05-27 01:00 471 查看
1. 创建透明图片(新建继承NSObject 的ImageUtil类)

+ (UIImage*)imageWithColor:(UIColor*)color size:(CGFloat)size

{
    CGRect rect =CGRectMake(0.0f,0.0f,
size, size);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context =UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [colorCGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *theImage =UIGraphicsGetImageFromCurrentImageContext(
4000
);
    UIGraphicsEndImageContext();
    return theImage;
}

2. 设置导航栏

UIImage *gradientImage44 = [ImageUtilimageWithColor:[UIColorcolorWithRed:1green:0blue:0alpha:0.5]size:1];
 UIImage *gradientImage32 = [ImageUtilimageWithColor:[UIColorcolorWithRed:1green:0blue:0alpha:0.5]size:1];

[[UINavigationBarappearance]
setBackgroundImage:gradientImage44forBarMetrics:UIBarMetricsDefault];
    [[UINavigationBarappearance]
setBackgroundImage:gradientImage32forBarMetrics:UIBarMetricsLandscapePhone];
    [[UINavigationBarappearance]
setBarStyle:UIBarStyleDefault];

3.设置viewcontroller  放到viewDidLoad中

self.edgesForExtendedLayout =UIRectEdgeTop;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: