[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.