1、设置导航栏bar的背景为一个图片
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"header_nav"] forBarMetrics:0];
//如果图片宽度不够,则会出现拼凑或剪辑的情况出现,此时采用下面方法即可
UIImage *bgImage = [[UIImage imageNamed:@"header_nav"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0) resizingMode:UIImageResizingModeStretch];
[self.navigationController.navigationBar setBackgroundImage : bgImage forBarMetrics:UIBarMetricsDefault];
//如果有navigation的基类,在基类中的viewDidLoad应该写,如下:
//[[UINavigationBar appearance] setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
2、隐藏导航栏下面一条黑色的线
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
//如果有navigation的基类,在基类中的viewDidLoad应该写,如下:
//[[UINavigationBar appearance] setShadowImage:[UIImage new]];
3、生成一张纯色的图片
- (UIImage *)imageWithColor:(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 *pureImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return pureImage;
}
记录学习,持续更新