UISegmentedControl - altering height in Interface

2019-03-10 23:48发布

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

Whilst the segmented control allows me to alter its width I cannot alter its height in Interface Builder (that property is greyed out on 44 in the 'size' section of the property inspector).

I know that a UISegmentedControl can be crated with a custom height in code and added to a UITableViewCell. Is there any way to adjust the height of the segmented control in Interface Builder?

7条回答
欢心
2楼-- · 2019-03-11 00:31

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.

查看更多
登录 后发表回答