简体   繁体   English

在故事板中添加子视图

[英]Add subView in storyboard

In my program needs to create view, then create subView and add it in view. 在我的程序中需要创建视图,然后创建subView并在视图中添加它。 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. 选择子视图并在Storyboard的Objects Explorer中拖动视图条目。 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] 或者您可以使用“嵌入视图”菜单,如下图所示[来源: 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你以编程方式查看创建它将在未来的项目中帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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