[IOS] Code best practices Discussion for device screen judgment

Source: Internet
Author: User

Currently developed projects are written in code for historical reasons, so judging device size is an unavoidable task.

So far I have judged the size.

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

//Screen Size enumeration typetypedefNs_enum (Nsuinteger, Screensizetype) {iphone4size,//480Iphone5size,//568Iphone6size,//667Iphone6psize,//736};

Then write a static function to get the current size type:

+ (Screensizetype) Getscreensizetype {if(KScreenBounds.size.height = =736) {returnIphone6psize; }Else if(KScreenBounds.size.height = =667) {returnIphone6size; }Else if(KScreenBounds.size.height = =568) {returnIphone5size; }returnIphone4size;}

Then get this type by macro:

#define Kscreensizetype [Publicfunction Getscreensizetype]

Finally, use this when:

int 1 0;

It's not clear how everyone is going to make it. I hope we can comment on the discussion.


[IOS] Code best practices Discussion for device screen judgment

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.