最近做項(xiàng)目遇到一種需求: 需要將navigationBar設(shè)置為透明裕寨。效果如下:
我的做法是先隱藏原來的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上設(shè)置背景圖
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