Add subView in storyboard

11,309

Solution 1

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

Solution 2

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

Share:
11,309
user3424037
Author by

user3424037

Updated on June 27, 2022

Comments

  • user3424037
    user3424037 almost 2 years

    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?

    • user3424037
      user3424037 over 10 years
      Drag n drop add subView in self.view but I want in view.
    • Tarek Hallak
      Tarek Hallak over 10 years
      Drag and drop it on the view, or drop it in the left inspector.
    • user3424037
      user3424037 over 10 years
      How open left inspector?)
    • Tarek Hallak
      Tarek Hallak over 10 years
      ctr+cmd+right arrow, ctrl+cmd+left arrow
  • user3424037
    user3424037 over 10 years
    view and subView added in self.view. I remove subView from self.view, add it in view and then add view in self.view.
  • Mikerizzo
    Mikerizzo over 10 years
    try this: [subView removeFromSuperview]; UIView *aView = [[UIView alloc] init]; [aView addSubview:subView]; [self.view addSubview:aView];
  • user3424037
    user3424037 over 10 years
    are you kidding me? I want that I can do it. In first post write "without code"
  • Christophe Weis
    Christophe Weis over 8 years
    Could you elaborate? This does not seem to be very clear and precise.
  • RAGHUNATH
    RAGHUNATH over 8 years
    @Christophe Weis. If we go through the Storyboard,It won't provide design exactly how we want.so only we are writing code dynamically.This is shown clearly in this link raywenderlich.com/50317/… Pls Upvote if it is useful to you..
  • RAGHUNATH
    RAGHUNATH over 8 years
    Why you gave negative.