您的位置:首页 > 产品设计 > UI/UE

IOS UI 自定义navigationBar布局

2015-08-22 15:13 393 查看
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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios ui 布局