一:导航栏的背景颜色如何设置
控制器是UINavigationController
[self.navigationBar setBackgroundImage:[UIImage imageNamed:@"导航栏背景图"] forBarMetrics:UIBarMetricsDefault];
可以利用下面方法的得到各种颜色的背景图片
+ (UIImage *)buttonImageFromColor:(UIColor *)color WithSize:(CGSize)size {
CGRect rect = CGRectMake(0, 0, size.width, size.height);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
二:整体设置导航栏字体颜色
控制器是UINavigationController
[self.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];
三:设置返回按钮
控制器是UINavigationController
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
if (self.childViewControllers.count > 0) { // 如果push进来的不是第一个控制器
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage<