Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

replace view element in interface builder

Is there any convenient way of replacing a view with another in Interface builder?

I find it somewhat cumbersome to have to reset all auto layout constraints when I for example want to swap an UILabel for a UITextView.

like image 643
Erik Johansson Avatar asked Jun 05 '14 07:06

Erik Johansson


People also ask

How to add view in XIB?

Create a XIB FileRight click on the portion of the screen where your project's files are (view controller, storyboard, etc), and choose new file . Xcode will prompt you for which file type you'd like to create. Choose the View option under the user interface menu.

How to add constraints to view in xcode?

To create constraints select the button and click the Align icon in the auto layout menu. A popover menu will appear, check both “Horizontal in container” and “Vertically in container” options to center the button on the screen. Then click the “Add 2 Constraints” button. Run the application.

How to add constraints in Uikit?

To create a constraint between two views, Control-click one of the views and drag to the other. When you release the mouse, Interface Builder displays a HUD menu with a list of possible constraints.

How do I change the size of a view in Interface Builder?

By default, Interface Builder uses the size returned from the view’s intrinsicContentSize method. However, if you need a different size at design time, you can set a placeholder intrinsic content size. This placeholder affects the size of the view only in Interface Builder.

How does Interface Builder work?

Interface Builder intelligently selects the set of constraints based on the items you are constraining and the direction of your drag gesture. If you drag more or less horizontally, you get options to set the horizontal spacing between the views, and options to vertically align the views.

How do I use the layout guide in Interface Builder?

Interface Builder automatically offers the top and bottom layout guides as options when creating constraints to the root view’s top or bottom edge as appropriate. If the layout guide is the view’s nearest neighbor, Interface Builder uses the guide by default.

Should I line up the views with constraints in Interface Builder?

Therefore, you need to position the views carefully before you draw the constraints. If you line up the views based on Interface Builder’s guidelines, you should end up with a reasonable set of constraints. If necessary, you can always edit the constraints afterward.


1 Answers

The "easiest" way to do this so far is to edit the raw xib file in a text editor and just replace the elements there.

like image 89
Erik Johansson Avatar answered Oct 24 '22 05:10

Erik Johansson