在ios中自定义导航栏
我用导航控制器&导航栏在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];
的尝试代码问题:有两个按钮之间的空间。
我该如何做到这一点?
只需使用分段控制:你有一个完整的例子HERE
但在段控制我不是能够设置自定义图像:( – user2893370 2014-09-19 07:07:10
@ user2893370不,你可以自定义SegmentedControl检查http://*.com/questions/21603822/ios-6-uisegmentedcontrol-with-ios-7-design和http:// *。 COM /问题/ 18900034 /使用-IOS-6式分段 - 控制 - 在-IOS-7 – 2014-09-19 07:22:25
声明分段控制与自定义视图
UISegmentedControl *control = (UISegmentedControl *) [segmentBarButton customView];
,然后将它添加到barbuttonitem视图
UIBarButtonItem *segmentBarButton=[[UIBarButtonItem alloc] initWithCustomView:control];
别忘了写e线涉及到段控制自定义视图像ur的要求添加红色或黑色图像段0或1.
澄清我,你想使用段控制作为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