20

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?

4

7 回答 7

39

您还可以xib在任何文本编辑器中打开该文件,例如 Dashcode 或 MacVim 或 TextEdit - 它是一个 XML。然后在那里找到你的元素,在我的例子中它看起来像:

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

然后你可以把它44改成你想要的任何高度——你会看到 IB 的变化。

这适用于所有无法在 IB 中更改高度的元素 -UIPicker也...

于 2010-12-31T22:20:30.590 回答
35

当您在 Interface Builder 中固定“高度”时,您可以间接更改它(选择段控件,然后通过菜单选择Editor -> Pin-> Height)。

这会将一个新的高度约束添加到该控件的约束列表中,然后您可以对其进行编辑。更改直接反映在 InterfaceBuilder 中,如下面的屏幕截图所示。

界面构建器高度约束

于 2012-12-20T16:26:40.710 回答
10

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

于 2010-01-26T16:25:00.717 回答
2

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

于 2010-01-26T15:57:28.737 回答
2

要在 Interface Builder 中执行此操作,您可以在“用户定义的运行时属性”下选择控件并添加框架属性

在界面构建器中添加框架属性

于 2014-08-30T21:23:49.507 回答
1

我想补充肯德的答案。

如果您使用故事板而不是 XIB,则需要添加:

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

我猜这个 id 可以是任何独特的东西。也许选择一些ID并修改一个字母?

这是完整的代码

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

我添加了一个 userLabel,以便我可以轻松找到这些东西。

注意:阅读故事板非常有启发性。更改情节提要文件非常危险。

于 2012-10-12T03:24:35.227 回答
1

我们可以设置自动布局,然后设置高度,然后我们可以关闭自动布局。所以它将有助于其他然后 ios 6.0 。

于 2013-07-27T03:49:59.820 回答