我用導航控制器&導航欄在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