Question

In my program needs to create view, then create subView and add it in view. I create view and subView in storyboard. Then in code:

[subView removeFromSuperview];
[view addSubview:subView];
[self.view addSubview:view];

How can I add subView to view in storyboard without code?

Was it helpful?

Solution

You don't actually need to write any code for this. There are many ways to do this:

  1. Select the subview and drag over the view entry in the Objects Explorer of storyboard. Once you leave the mouse hold, the parent view will have a triangle indicating your subview has become its child and the subview will have a bigger indent than your view

  2. Or you can use the "Embed in View" menu as shown in the below pic [source:http://codesheriff.blogspot.co.il/2014/03/8-tips-for-working-effectively-with.html]

enter image description here

OTHER TIPS

open file inspector ->search for view drag and Drop the view in storyboard

enter image description here

so in this you already holding a view now you adding an view its almost like adding a sub view to the main view this is for adding view without code

Open the storyboard and just create the new view inside the subview.

What your doing above is doing nothing.

[subView removeFromSuperview]; //Your removing subview from the superview
[view addSubview:subView]; //is view a new UIView?
[self.view addSubview:view];

You Will have a View in the bottom of right side.You Just drag and Drop the view Where you Want.To Set constriants clearly We are goin Dynamic view Creation.If you do View creation programmatically it will help you in the future project.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top