1、UINavigationBar 背景透明(按键还看得到)
[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
2、列表上拉,UINavigation背景颜色逐渐变深
思路:上拉的时候不断改变背景颜色的alpha值
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
CGFloat yoffset = scrollView.contentOffset.y;
if (yoffset >0) {
CGFloat alpha = MIN(1, yoffset/150); //150:上拉150距离背景图片alpha=1
UIImage *image = [self createImageWithColor:[UIColor colorWithRed:73/255.0f green:174/255.0f blue:175/255.0f alpha:alpha]];
[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
}
}
- (UIImage *) createImageWithColor: (UIColor *) color
{
CGRect rect = CGRectMake(0.0f,0.0f,1.0f,1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context =UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *myImage =UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return myImage;
}