简体   繁体   English

具有固定高度的@IBDesignable UIView

[英]@IBDesignable UIView with fixed height

I have a custom control (xib + UIView subclass). 我有一个自定义控件(xib + UIView子类)。

I'd like my control to have a computed height, like UITextField or ProgressBar, so I'd like IB not to show me the UIView resize knobs on each side, but only on the left and right of my custom control. 我希望控件具有经过计算的高度,例如UITextField或ProgressBar,所以我希望IB不要在我的自定义控件的左右两侧显示UIView调整大小旋钮。 In UITextField height field in property inspector is ghosted, so you can't modify it from Interface Builder. 在UITextField中,属性检查器中的height字段被重影,因此无法从Interface Builder对其进行修改。

I searched StackOverflow, and found this Make a fixed size UIView, like UISwitch (using IBDesignable) , but it isn't what I am trying to achieve. 我搜索了StackOverflow,并发现它制作了一个固定大小的UIView,例如UISwitch(使用IBDesignable) ,但这不是我想要实现的目标。

Thank you for your help, Luca- 谢谢您的帮助,卢卡-

I believe that you want to disable height in Size inspector in right utilities panel, just for your custom control like segment control and fixed height text field. 我相信您想在右侧实用程序面板的“大小”检查器中禁用高度,仅用于您的自定义控件,例如细分控件和固定高度的文本字段。 As of now, this is not possible. 到目前为止,这是不可能的。 Using IBInspectable, you will only be able to display your variables in Attribute Inspector. 使用IBInspectable,您将只能在Attribute Inspector中显示变量。 The other option you have is to resize your control within the code, every time it loads. 您还有另一个选择,就是每次加载代码时都在代码中调整控件的大小。

One way to accomplish what you want is to add height and width constraints on the view using Auto Layout . 一种实现所需功能的方法是使用“ 自动布局”在视图上添加高度和宽度约束。 You can add an IBOutlet to the constraints in Interface Builder in case you need to manipulate them at run time. 您可以将IBOutlet添加到Interface Builder中的约束,以防您需要在运行时对其进行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM