iOS Development screen adaptation problem solution

Source: Internet
Author: User

Tagged with: Xcode ios screen adaptation UI

There are four solutions for screen adaptation: (1) According to the screen width and height write control frame (2) The use of autoresizing (Chinese Policy), (3) The use of AutoLayout (the best Policy); (4) sizeclasses+ The use of AutoLayout (the best policy). The following will be described separately.


(1) According to the width and height of the current screen to write frame

In the new feature interface, according to: [UIScreen mainscreen].bounds.size.height. To determine the user's screen length, to determine the 3.5-inch, 4-inch, 4.7-inch, 5.5-inch, in order to set the new features in the picture to choose which set.

Common wording:

#define JKSCREENW [UIScreen mainscreen].bounds.size.width

CGFloat BTNW = jkscreenw * 0.2;

Cons: Code is complex, error prone, and maintenance difficult, flexibility is very poor.


(2) Autoresizing use

Before AutoLayout, there are autoresizing can do screen adaptation, but the limitations are large, only for the parent-child relationship limited adjustment, such as fixed margin, size variable, the adjustment of the Brotherhood can not be achieved. For apps that have a fixed UI, this approach is basically satisfying. By contrast, AutoLayout is much more powerful than autoresizing.


(3) AutoLayout use

-How did the previous iOS program layout the UI?

Often write a large number of coordinate calculation code;

To ensure a perfect UI effect on a variety of screens, it is sometimes necessary to write different coordinate calculation codes for several screens (the legendary "screen Fit")


-What is AutoLayout?

AutoLayout is an "auto-layout" technique designed to lay out the UI interface.

AutoLayout since IOS6 began to introduce, due to the Xcode4 of the force, at that time did not get a great promotion.

Since the beginning of iOS7 (XCODE5), the development efficiency of AutoLayout has been greatly improved.

Apple also recommends that developers use AutoLayout to layout the UI interface.

AutoLayout can easily solve the problem of screen adaptation.


(4) Size classes use

The new size classes feature in IOS8 is an abstraction of the size of all current iOS devices.

Usage:

The width and height of the screen are divided into three cases: (Compact,regular,any). That is, compact, normal and arbitrary. This width and height 33 integration, altogether nine kinds of situation. For each case, if necessary, we can set the automatic layout constraints of the UIView in storyboard or xib alone, even if a button is displayed easily.

The specific use of the method after we use the actual project for further analysis.


This article refers to the Geek College video course "IOS8 SDK new features series course", Thank you very much!

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

iOS Development screen adaptation problem solution

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.