简体   繁体   English

如何以编程方式显示UISegmentedControl?

[英]How do I programmatically display a UISegmentedControl?

I'm looking at an iPhone application, with several ViewControllers controlled by a UINavigationController. 我正在看一个iPhone应用程序,其中有几个由UINavigationController控制的ViewController。

Somewhere deep down one of the ViewControllers is creating a view, and the view is trying to pop a 在某个ViewController的某个深处某个地方正在创建一个视图,而该视图正试图弹出一个

UISegmentedControl *segmentedControl 

up on top of itself like so: 像这样:

[self.window addSubview:segmentedControl];

"self" is a specialized form of UIView, and the control's frame is set “ self”是UIView的一种特殊形式,并且设置了控件的框架

 segmentedControl.frame = someFrame;

For some reason, the control is not showing up on top of the current view. 由于某种原因,该控件未显示在当前视图的顶部。 Should this work, and, if it should, what are the most likely causes of trouble? 这应该起作用,如果应该起作用,最有可能引起麻烦的原因是什么?

When you say self is a specialized form of UIView I'm guessing you are referring to a UIView custom subclass. 当您说self是UIView的一种特殊形式时,我猜您是在指的是UIView自定义子类。

If you are adding the UISegmentedControl from within this view, you want to do the following: 如果要从此视图中添加UISegmentedControl,则需要执行以下操作:

[self addSubview:segmentedControl];

You set it's frame relative to it's superview, so if you want it on the top left corner you would do: 您将其框架设置为相对于其全景视图,因此,如果要在左上角使用它,则可以执行以下操作:

segmentedControl.frame = CGRectMake(0.0f, 0.0f, someWidth, someHeight);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM