TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Mar 2016 |
Maintained by huang-kun.
If you have seen a self-defined macro like this:
#define iPhone6 CGSizeEqualToSize([UIScreen mainScreen].currentMode.size, CGSizeMake(750, 1334))
It's maybe not a good idea to define a device version by it's screen pixel size, because when your iPhone6 is being a display zoom mode (which can be changed in settings), the screen pixel size is 640x1136 as same as iPhone5. So using this macro is not correct.
When you design a interface that specifically for iPhone6, yon don't need to know it's really an iPhone6 because the information you need is the screen resolution.
Here is a solution:
typedef NS_ENUM(NSInteger, UIScreenDisplayResolution) {
UIScreenDisplayResolutionUndefined,
// iPhone (includes iPod Touch)
UIScreenDisplayResolutionPixel320x480, // older type
UIScreenDisplayResolutionPixel640x960, // 4, 4s
UIScreenDisplayResolutionPixel640x1136, // 5, 5s, 6(display zoom), 6s(display zoom), SE 1
UIScreenDisplayResolutionPixel750x1334, // 6, 6s
UIScreenDisplayResolutionPixel1125x2001, // 6+(display zoom), 6s+(display zoom)
UIScreenDisplayResolutionPixel1242x2208, // 6+, 6s+
// iPad
UIScreenDisplayResolutionPixel768x1024, // 1, 2, mini 1
UIScreenDisplayResolutionPixel1536x2048, // 3, 4, Air(1, 2) mini(2, 3, 4), Pro 2<9.7-inch>
UIScreenDisplayResolutionPixel2048x2732, // Pro (1, 2<12.9-inch>)
};
Pick up an option, then use it for a lot of devices.
There is another type of enum which may help you out for convenience screen display aspect ratio calculation.
typedef NS_ENUM(NSInteger, UIScreenDisplayAspectRatio) {
UIScreenDisplayAspectRatioUndefined,
UIScreenDisplayAspectRatio_3_2, // 3:2
UIScreenDisplayAspectRatio_4_3, // 4:3
UIScreenDisplayAspectRatio_16_9, // 16:9
};
UIScreen_YJ is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "UIScreen_YJ"
huang-kun, [email protected]
UIScreen_YJ is available under the MIT license. See the LICENSE file for more info.