2012-01-10 60 views
0

我需要调整段控制器中每个段的宽度。调整段控制器段的宽度

我试过了;

segment.apportionsSegmentWidthsByContent = YES; 

它工作!但是这只支持iOS 5,我需要我的应用程序来支持iOS 4。那么什么是apportionsSegmentWidthsByContent的iOS 4等效物?

回答

3

我不相信它可以自动完成;你需要测量出正确的宽度,并调用setWidth:forSegmentAtIndex:每个段,基于文本的控制量:

http://developer.apple.com/library/ios/documentation/uikit/reference/UISegmentedControl_Class/Reference/UISegmentedControl.html#//apple_ref/occ/instm/UISegmentedControl/setWidth:forSegmentAtIndex

+0

我试过'setWidth:forSegmentAtIndex:'但它没有工作。 – sharon 2012-01-10 17:05:26

+0

你交给'setWidth:forSegmentAtIndex:'的参数是什么?如果你调用'widthForSegmentAtIndex:',它是否会返回你的新值? – Fletch 2012-01-10 17:08:23

+0

我不想劫持Fletch的答案,但尝试:[segment setWidth:45 forSegmentAtIndex:0]; [segment setWidth:15 forSegmentAtIndex:1]; – ader 2012-01-10 17:12:07

1

您可以进行细分自动化到他们的内容。 因此,如果有必要,请在您的细分图标内容中使用透明png来强制指定宽度。

更好的是,请参阅上面的Fletch答案。卫生署。

+0

难道没有其他办法可以做到吗?像是没有像iOS 5中的功能,我可以调用呢? 'setWidth:forSegmentAtIndex:'也不起作用。 – sharon 2012-01-10 17:06:15

+0

我在上面给Fletch的回答发表了一个评论。 – ader 2012-01-10 17:13:40