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