简体   繁体   中英

@IBDesignable UIView with fixed height

I have a custom control (xib + UIView subclass).

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. In UITextField height field in property inspector is ghosted, so you can't modify it from 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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