- navigationBar背景设置
//1. 配置navigationBar背景图片
[self.navigationController.navigationBar setBackgroundImage:[UIImage
imageNamed:@"header_bg.png" ]
forBarMetrics:UIBarMetricsDefault];
- 设置中间标题图片
//2.配置中间标题为图片
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 60, 35)];
imageView.image = [UIImage imageNamed:@"logo_title.png"];
self.navigationItem.titleView=imageView;
- 设置navigationBar左右按钮
navigationBar按钮常见样式有三种,分别为文本样式、系统样式、自定义样式
1.文本样式
UIBarButtonItem *textItem = [[UIBarButtonItem alloc] initWithTitle:@"分类"
style:UIBarButtonItemStylePlain target:self
action:@selector(dealConfig:)];
2.系统样式
UIBarButtonItem *systemItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self
action:@selector(dealConfig:)];
3.自定义样式
UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
leftButton.frame = CGRectMake(0, 0, 45, 30);
[leftButton setBackgroundImage:[UIImage imageNamed:@"photo_left_nav.png"] forState:UIControlStateNormal];
[leftButton addTarget:self action:@selector(dealConfig:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
4.添加到界面上
self.navigationItem.leftBarButtonItem = leftItem;
self.navigationItem.rightBarButtonItem = rightItem;
版权声明:本文为博主原创文章,未经博主允许不得转载。