Some ways to fit different display sizes of iphone devices

Source: Internet
Author: User

------Understanding of adaptation------

1. What is a fit?

Adaptation is to adapt to different hardware and system software, hardware including screen display, processor, memory and so on (currently mainly screen adaptation, the IPhone 6s new 3D touch features, other hardware features have not changed substantially), The software is mostly different iOS systems (some of the methods that are no longer supported in the latest system (which is usually as backwards-compatible as possible) need to be judged).

2. Why should we fit?

The adaptation is to be compatible with different devices.

3. What are the main ways of screen adaptation?

(1) Proportional adaptation (all views scaled by screen size, relative position unchanged): A, pure code, B, Code +storyboard (do not use automatic layout), C, code +storyboard (using automatic layout).

(2) Free adaptation (mainly using automatic layout): Because the same layout in different sizes of the screen display effect is not the same, if only equal to zoom, sometimes the display effect is not satisfactory, in the display content size in line with the operating habits (this look at yourself) Screen size The biggest difference is the screen large display content (such as browsing news, except for some fixed images, controls, etc.), a, the spacing and relative size of the content of the constraint, B, the width and relative position of the constraint content, C, the constraints of the content of the spacing, width and height.

Some methods of------adaptation------

Situation One

(equal to Fit, code +storyboard, do not use automatic layout, it is recommended to use IPhone6 size layout), by obtaining the screen size, redefining the cgrectmake, updating all views and their sub-views of the frame, complete and so on. Note fonts, pictures, and TableView, CollectionView.

1 、—————— AppDelegate.h added:

+ (void) Ergodicview: (UIView *) view;

2 、—————— APPDELEGATE.M added:

#define ScreenHeight [UIScreen mainscreen].bounds.size.height

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

#define SCREENSCALEX (screenwidth/375)//relative to the Apple 6 screen

#define Screenscaley (screenheight/667)

Auto-fit Storyboard all views by screen

+ (void) Ergodicview: (UIView *) view{

if (View.subviews.count! = 0) {

For (UIView *temp in view.subviews) {

Temp.frame = CGRectMake1 (temp.frame.origin.x, TEMP.FRAME.ORIGIN.Y, Temp.frame.size.width, temp.frame.size.height);

[Self ergodicview:temp];

}

}

}

Modify CGRectMake

Cg_inline CGRect

CGRectMake1 (CGFloat x, cgfloat y, cgfloat width, cgfloat height)

{

CGRect rect;

rect.origin.x = x * SCREENSCALEX;

RECT.ORIGIN.Y = y * Screenscaley;

Rect.size.width = width * SCREENSCALEX;

Rect.size.height = height * Screenscaley;

return rect;

}

--------------------

Situation Two

After you use the AutoLayout layout, you can reset the view's frame. When the viewdidload is loaded, the frame of the view is delayed, and no delay is reset by storyboard. You can also reset the frame in viewdidlayoutsubviews or viewdidappear

Some ways to fit different display sizes of iphone devices

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.