我用导航控制器&导航栏在StroryBoard。在ios中自定义导航栏
我想为导航栏的右侧定制一个视图的导航栏。
我试图代码
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];
的尝试代码问题:有两个按钮之间的空间。
我该如何做到这一点?
澄清我,你想使用段控制作为barbuttonitem。我对吗? – sreekanthk 2014-09-19 07:02:51
@sreekanthk,是的,你是对的 – user2893370 2014-09-19 07:03:31
然后yru使用两个按钮,而不是采取UISegmentControl – sreekanthk 2014-09-19 07:05:04