IOS AutoLayout (1) and iosautolayout

Source: Internet
Author: User

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:

  • Storyboard
  • Code

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.