[IOS] Code for device screen judgment best practices solution discussion, ios Best Practices

Source: Internet
Author: User

[IOS] Code for device screen judgment best practices solution discussion, ios Best Practices

Currently, the development project uses code to write the UI for historical reasons, so it is inevitable to determine the device size.

Currently, I am doing this to determine the size.

First, define an enumeration class that contains all the dimension types:

// The screen size Enumeration type typedef NS_ENUM (NSUInteger, ScreenSizeType) {iPhone4Size, // 480 iPhone5Size, // 568 iPhone6Size, // 667 iPhone6pSize, // 736 };

Then write a static function to obtain the current dimension type:

+ (ScreenSizeType) getScreenSizeType {if (kScreenBounds. size. height = 736) {return iPhone6pSize;} else if (kScreenBounds. size. height = 667) {return iPhone6Size;} else if (kScreenBounds. size. height = 568) {return iPhone5Size;} return iPhone4Size ;}

Then you can use the macro to obtain this type:

# Define kScreenSizeType [PublicFunction getScreenSizeType]

Finally, use the following code:

Int a = kScreenSizeType = iPhone6pSize? 1: 0;

It is unclear how we implement it. I hope you can comment on it.


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.