自定义UINavigationBar背景方法

http://www.devdiv.com/uinavigationbar_-blog-21666-9081.html



http://blog.csdn.net/chang6520/article/details/7918877

2、自定义 高度 背景 UINavigationBar (修改系统自带的) 

在BaseVC中
#import "BaseViewController.h"

@implementation BaseViewController
- (void)viewWillAppear:(BOOL)animated{
    [self.navigationController.navigationBar setFrame:CGRectMake(0, 20, 320, 40)];
    for (UIView *view in self.navigationController.view.subviews) {
        if (![view isMemberOfClass:[UINavigationBar class]]) {
            [view setFrame:CGRectMake(0, -4, 320, 484)];//这里调整内容区域大小位置
        }
    }
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"blue_navigation_color.png"] forBarMetrics:UIBarMetricsDefault];
}


//恢复系统默认

//[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"back_01.png"]];
    }
    return self;
}

3、 修改导航的后退按钮
        UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 60, 40)];
        [backButton setBackgroundImage:[UIImage imageNamed:@"nav_back_button.png"] forState:UIControlStateNormal];
        [backButton addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside];
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];

- (void)dismiss {
    [self.navigationController popViewControllerAnimated:YES];
}


你可能感兴趣的:(自定义UINavigationBar背景方法)