上文中,我们在Storyboard中实现了HelloWorld,今天我们来深入的认识一下。
Toolbar
首先,将Toolbar拖入到Window当中,运行,效果如图所示:

运行后,大家可点击一下各个按钮看看效果,具体属性操作后续再来具体讲解。

ViewController
删掉原本的ViewController,重新拖出一个控制器,与Window建立联系(鼠标右键点击图示位置,拉至ViewController,选择window content)

如下图所示,将控件拖入Storyboard中

编译后可发现,界面并没有进行很好的适配,此时,该Auto Layout上场了。
Auto Layout
1、先给Custom View设置向左、向下、向右、高度的约束,使其固定在界面最下方:

2、接下来,针对Container View,设置:向上、向左、向右、针对Custom View向下:

3、在left和right所处的ViewController中,针对left和right标签,制定约束,使其保持居中:

至此,约束完成,cmd+R编译后,如下图所示,随意拖动,UI均有适配:

网友评论