如何使用 Storyboard 将 UISegmentedControl 添加到我的 UIToolbar? [英] How do I add a UISegmentedControl to my UIToolbar using Storyboard?

查看:29
本文介绍了如何使用 Storyboard 将 UISegmentedControl 添加到我的 UIToolbar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 我正在尝试向下面的 UIToolbar 添加一个分段控件,但是当我尝试将它拖到 Storyboard 中时,它会替换我的 Table View.
  2. 此外,当我尝试将 UIBarButton 添加到我的工具栏时,它会将我的原型单元向下推......我的视图层次结构是否错误?
  3. 无论如何,当我添加一个 UIBarButton 项目时,在模拟器中,工具栏不像我在导航控件检查器中设置的那样是黑色透明的.这是怎么回事?

谢谢!

推荐答案

1 - 以编程方式执行.您需要先为您的 UIToolbar 分配一个框架,然后您可以在其中添加元素(segmentedControl).我建议使用 UIBarButtonItems,它们基​​本上是一样的.

1 - Do it programmatically. You need to assign a frame to your UIToolbar first, then you can add elements in it (the segmentedControl). I suggest though to use UIBarButtonItems, which basically are the same.

要将其坚持到底,请尝试这样做:

To stick it to the bottom, try to do this way:

#define SCREEN_FRAME [[UIScreen mainScreen] applicationFrame]

CGRect frame = CGRectMake(0, [[UIScreen mainScreen] bounds].size.height - 44, [[UIScreen mainScreen] bounds].size.width, 44);
UIToolbar *toolBar = [[UIToolbar alloc]initWithFrame:frame];
toolBar.frame = CGRectMake(0,self.view.frame.size.height-toolBar.frame.size.height,SCREEN_FRAME.size.width,toolBar.frame.size.height);

//Setting up the items

UIBarButtonItem *first = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"image.png"] style:UIBarButtonItemStylePlain target:self action:@selector(yourAction:)] autorelease]; 
UIBarButtonItem *second = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"image.png"] style:UIBarButtonItemStylePlain target:self action:@selector(yourAction:)] autorelease]; 

//Creating an array with the items
NSArray *items = [NSArray arrayWithObjects:first,second, nil];

//Assigning the array to the toolBar
[toolBar setItems: items];

然后你可以设置它的样式

Then you can set its style with

mytoolbar.barStyle = UIBarStyleBlack;

2 - 同上,取景.

3 - 您需要将导航控制器样式设置为黑色.
使用 self.navigationController.navigationBar.style = UIBarStyleBlack;,或在 IB 中选择按钮,然后从 Inspector 中将 Tint 或 Style 设置为您想要的任何内容.

3 - You need to set your navigationController style to Black.
Use self.navigationController.navigationBar.style = UIBarStyleBlack; ,or in IB choose the buttons and from Inspector set Tint or Style to whatever you want.

同时检查这个问题

这篇关于如何使用 Storyboard 将 UISegmentedControl 添加到我的 UIToolbar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆