A discussion of best practice scenarios for device screen judgment by iOS code

Source: Internet
Author: User

The current development of the project for historical reasons are written in code UI, so judging equipment size has become an unavoidable task.

This is how I judge the size at the moment.

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

Enumeration types for screen dimensions typedef ns_enum (Nsuinteger, Screensizetype) {iphone4size,//Iphone5size 568, Ne6psize,//736};

Then write a static function to get 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 iPh One4size;}

And then get this type through the macro:

#define KSCREENSIZETYPE [Publicfunction Getscreensizetype]

Finally, when used this way:

int a = Kscreensizetype = = iphone6psize? 1:0;

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.