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条回答
可以哭但决不认输i
2楼-- · 2019-03-11 00:16

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

查看更多
The star\"
3楼-- · 2019-03-11 00:17

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

查看更多
趁早两清
4楼-- · 2019-03-11 00:22

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

查看更多
别忘想泡老子
5楼-- · 2019-03-11 00:23

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

查看更多
该账号已被封号
6楼-- · 2019-03-11 00:25

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...

查看更多
做自己的国王
7楼-- · 2019-03-11 00:29

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

查看更多
登录 后发表回答