我在 StroryBoard 中使用了 Navigation Controller 和 navigation Bar。
我想为一个 View 自定义导航栏,如下所示,用于导航栏的右侧。
我试过的代码
UIButton *btn_list=[UIButton buttonWithType:UIButtonTypeCustom];
btn_list.frame=CGRectMake(0, 0, 60, 30);
[btn_list setTitle:@"Liste" forState:UIControlStateNormal];
[btn_list setBackgroundImage:[UIImage imageNamed:@"red-left.png"] forState:UIControlStateNormal];
[btn_list setBackgroundImage:[UIImage imageNamed:@"black-left.png"] forState:UIControlStateSelected];
UIBarButtonItem *list_bar=[[UIBarButtonItem alloc]initWithCustomView:btn_list];
UIButton *btn_map=[UIButton buttonWithType:UIButtonTypeCustom];
btn_map.frame=CGRectMake(0, 0, 60, 30);
[btn_map setTitle:@"Karte" forState:UIControlStateNormal];
[btn_map setBackgroundImage:[UIImage imageNamed:@"red-right.png"] forState:UIControlStateNormal];
[btn_list setBackgroundImage:[UIImage imageNamed:@"black-right.png"] forState:UIControlStateSelected];
UIBarButtonItem *map_bar=[[UIBarButtonItem alloc]initWithCustomView:btn_map];
self.navigationItem.rightBarButtonItems=[[NSArray alloc]initWithObjects:list_bar,map_bar, nil];
试过的代码问题:两个按钮之间有一个空格。
我怎样才能做到这一点?
最佳答案
只要使用分段控制:你有一个完整的例子HERE
关于ios - ios自定义导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25928097/