简体   繁体   中英

Add subView in storyboard

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?

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]

在此输入图像描述

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

在此输入图像描述

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];

你将在右侧底部有一个视图。你只需拖放视图你想要的地方。清楚地设置constriants我们是动态视图Creation.If你以编程方式查看创建它将在未来的项目中帮助你。

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