You can 将背景图像设置为导航栏使用这个
Put in didFinishLaunchingWithOptions
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"title_bar.png"] forBarMetrics:UIBarMetricsDefault];
或者你可以设置导航栏图像在任何视图中使用
UINavigationBar *navBar = [[self navigationController] navigationBar];
UIImage *image = [UIImage imageNamed:@"TopBar.png"];
[navBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault];
或者你可以在导航栏上设置视图 Link https://stackoverflow.com/questions/13890062/set-titleview-for-all-navigationcontroller-and-navigationitem/13890354#13890354
[[UINavigationBar appearance] addSubview:yourView];
or
self.navigationItem.titleView = YourView;
And 设置标题 using h
self.navigationItem.title = @"Your Title";
你可以使用这个来获取navigationBarButton
-(void)getRightBarBtn
{
UIButton *Btn =[UIButton buttonWithType:UIButtonTypeCustom];
[Btn setFrame:CGRectMake(0.0f,0.0f,68.0f,30.0f)];
[Btn setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"yourImage.png"]] forState:UIControlStateNormal];
//[Btn setTitle:@"OK" forState:UIControlStateNormal];
//Btn.titleLabel.font = [UIFont fontWithName:@"Georgia" size:14];
[Btn addTarget:self action:@selector(yourBtnPress:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithCustomView:Btn];
[self.navigationItem setRightBarButtonItem:addButton];
}
并在导航栏上设置简单的imageView
UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"star.png"]];
UIBarButtonItem *backBarButton = [[UIBarButtonItem alloc] initWithCustomView:image];
self.navigationItem.rightBarButtonItem = backBarButton;