UISegmentedControl - altering height in Interface Builder

前提是你 提交于 2019-12-02 20:32:31
David Kanarek

No, it must be done in code. See this question.

You can also open the xib file in any text editor, like Dashcode or MacVim or TextEdit - it's an XML. Then find your element there, in my case it looked like:

<object class="IBUISegmentedControl" id="270020637">
    [...]
    <string key="NSFrame">{{20, 154}, {176, 44}}</string>
    [...]
</object>

Then you can change the 44 into whatever height you want - you'll see the changes in IB.

This works for all elements that can't be changed height in IB - UIPicker also...

You can indirectly change it when you pin the "Height" in Interface Builder (select the segment control then via the menu select Editor -> Pin-> Height).

This will add a new Height constraint to the list of constraints for that control which you can then edit. Changes directly reflect in InterfaceBuilder as you can see in the Screenshot below.

I'm not sure in IB, but you could always find the cell in your code and programmatically adjust its UISegmentedControl's height.

To do it inside Interface Builder you can select the control and add frame attribute under "User Defined Runtime Attributes"

I want to add to Kender's answer.

If you use storyboard rather than XIB, you will need to add:

                                <constraint firstAttribute="height" constant="10" id="9Wo-6S-8EM"/>
                                <constraint firstAttribute="width" constant="201" id="lw7-cq-3XN"/>

The id can be anything unique I guess. Maybe pick some ID and modify one letter?

This is the full code

<segmentedControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="RMR-XS-abw" userLabel="ngentot2">
                        <constraints>
                            <constraint firstAttribute="height" constant="10" id="9Wo-6S-8EM"/>
                            <constraint firstAttribute="width" constant="201" id="lw7-cq-3XN"/>
                        </constraints>
                        <segments>
                            <segment title="First"/>
                            <segment title="Second"/>
                        </segments>
                    </segmentedControl>

I add a userLabel so I can easily find the stuff.

Note: reading the storyboard is very enlightening. Changing storyboard file is VERY dangerous.

We can set autolayout and then set height, After that we can off autolayout. so It will help for other then ios 6.0 .

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!