【发布时间】:2014-09-19 06:58:05
【问题描述】:
我在故事板中使用了导航控制器和导航栏。
我想为一个视图自定义导航栏,如下导航栏右侧。
我尝试过的代码
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];
试过代码的问题:两个按钮之间有空格。
我怎样才能做到这一点?
【问题讨论】:
-
请澄清您想将段控件用作条形按钮项。我说的对吗?
-
@sreekanthk,是的,你是对的
-
然后你使用两个按钮而不是使用 UISegmentControl
-
但在分段控制中我无法设置自定义图像。:(
-
缩小你的图片大小,
标签: ios objective-c iphone xcode uinavigationcontroller