IOS AutoLayout (1) and iosautolayout
Original Blog, reprinted, please indicate the source
Blog.csdn.net/hello_hwc
Preface:
AutoLayout is a key technology to adapt the UI to adaptive device size changes of controls. With the increasing size of IOS devices, it is difficult to use fixed numbers to arrange the UI as before.
There are two ways to implement AutoLayout:
There are three optional methods to implement using Storyboard
- Blue reference line for XCode to automatically create
- Drag and Drop
- Key configuration for some options in XCode
The content of this article includes
- Some basic knowledge on Storyboard
- Create AutoLayout Based on the blue reference line
In the next article, we will continue to update and use Storyboard to create AutoLayout. Then, we will use an article to explain how to use Code to implement AutoLayout.
StoryBoard preparation
1. Storyboard selection for different devices
When a program serves devices of different sizes at the same time, it is sometimes configured as a different Storyboard, And the storyboard button is selected in the wAny hAny (width Any; height Any) in the red circle. By default, a Storyboard applies to all devices.
Click wAny hAny, as shown in. The section in the Red Circle describes which devices are currently Storyboard.
2. preview the View on the Storyboard.
Preview View is important for AutoLayout because it takes too much time to Run-Debug each time.
Open the secondary editing window. (Command + Option + EnterShortcut Key)
Then, follow the animation below
Open the secondary editing window.
The following is a simple auxiliary editing window to view the effects of different devices.
XCode automatically creates AutoLayout
XCode can automatically create AutoLayout. Why should I use the blue reference line? The reason is that the automatically created Layout may be much different from the desired Layout if it is not based on the blue reference line.
Automatic creation process with blue reference line
1. place controls according to the blue reference line
We can see that the blue reference line appears during the drag process.
In this way, the effect is as follows:
As you can see, the screen is rotated, and the Button is always in the upper right corner.
Follow-up
I will update two more articles about AutoLayout. One will continue to explain how to create them on the Storyboard, and the other will explain how to implement them using Code.