iOS OC 设置透明navigationBar

最近做项目遇到一种需求: 需要将navigationBar设置为透明。效果如下:


iOS OC 设置透明navigationBar_第1张图片

我的做法是先隐藏原来的navigation:

self.navigationController.navigationBarHidden = YES;

然后添加一个navigationBar:

//添加一个UINavigationBar

CGRect screenRect = [[UIScreen mainScreen] bounds];

imageNavigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, screenRect.size.width, 64)];

[self.view addSubview: imageNavigationBar];


//往imageNavigationBar上设置背景图

UIImage *barImage = [UIImage imageNamed:@"bg_home_nav"];

UIImage *scaleBarImage = [[UIImage alloc] init];

scaleBarImage = [scaleBarImage image:barImage byScalingToSize:CGSizeMake(SCREEN_WIDTH, 64)];

[imageNavigationBar setBackgroundImage:scaleBarImage forBarMetrics:UIBarMetricsDefault];

imageNavigationBar.shadowImage = [UIImage new];

imageNavigationBar.translucent = NO;

gotta

你可能感兴趣的:(iOS OC 设置透明navigationBar)