UISegmentedControl - altering height in Interface Builder

后端 未结 7 647
萌比男神i
萌比男神i 2021-02-02 11:54

I\'m creating a number of static custom UITableViewCells and have dragged a UISegmentedControl onto one of the custom cells.

Whilst the segmen

相关标签:
7条回答
  • 2021-02-02 12:28

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

    0 讨论(0)
  • 2021-02-02 12:30

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

    0 讨论(0)
  • 2021-02-02 12:33

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

    add frame attribute inside interface builder

    0 讨论(0)
  • 2021-02-02 12:35

    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.

    interface builder height constraint

    0 讨论(0)
  • 2021-02-02 12:36

    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.

    0 讨论(0)
  • 2021-02-02 12:50

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

    0 讨论(0)
提交回复
热议问题