IOS-determine the current device model of the user (iPhone model)

Source: Internet
Author: User
Tags home screen

IOS-determine the current device model of the user (iPhone model)
Judgment Method: When we adapt to multiple models, we usually need to consider the model of the User device, and then determine the size of the control or Image Based on the width, height, and resolution of the User device. So how do I know the model of the user's device? I personally use (the following method) 1 [[UIScreen mainScreen] bounds]; To obtain the bounds of the home screen, A familiar friend will surely think of the CGRect struct as soon as he sees bound or frame, and bounds is also a variable of this struct, among which the CGRect member has a CGSize (also a struct ), CGSize members include width and height, so now we can get the width and height of the main screen. Then we can know the specific models used by users based on the data below: width * High portrait width * height iPhone4: 320*480 iPhone5: 320*568 iPhone6: 375*667 iPhone6Plus: 414*736 data can be found in the sample code in the complete guide for IOS device design: Here a category UIDevice + IPho of UIDevice is created. NeModel. h 1 typedef NS_ENUM (char, iPhoneModel) {// 0 ~ 3 2 iPhone4, // 320*480 3 iPhone5, // 320*568 4 iPhone6, // 375*667 5 iPhone6Plus, // 414*736 6 UnKnown 7 }; 8 9 @ interface UIDevice (IPhoneModel) 10 11/** 12 * return current running iPhone model13 * 14 * @ return iPhone model15 */16 + (iPhoneModel) iPhonesModel; 17 18 @ end UIDevice + IPhoneModel. m 1 # import "UIDevice + IPhoneModel. h "2 3 @ implementation UIDevice (IPhoneModel) 4 5/** 6 * return current running iP Hone model 7*8 * @ return iPhone model 9 */10 + (iPhoneModel) iPhonesModel {11 // bounds method gets the points not the pixels !!! 12 CGRect rect = [[UIScreen mainScreen] bounds]; 13 14 CGFloat width = rect. size. width; 15 CGFloat height = rect. size. height; 16 17 // get current interface Orientation18 UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; 19 // unknown20 if (UIInterfaceOrientationUnknown = orientation) {21 return UnKnown; 22} 23 24 // portrait width * height25 // iPhone4: 320*48026 // iPhone5: 320*56827 // iPhone6: 375*66728 // iPhone6Plus: 414*73629 30 // portrait31 if (UIInterfaceOrientationPortrait = orientation) {32 if (width = 3200000f) {33 if (height = 4800000f) {34 return iPhone4; 35} else {36 return iPhone5; 37} 38} else if (width = 375.0f) {39 return iPhone6; 40} else if (width = 414.0f) {41 return iPhone6Plus; 42} 43} else if (UIInterfaceOrientationLandscapeLeft = orientation | UIInterfaceOrientationLandscapeRight = orientation) {// landscape44 if (height = 320.0) {45 if (width = 480f) {46 return iPhone4; 47} else {48 return iPhone5; 49} 50} else if (height = 375.0f) {51 return iPhone6; 52} else if (height = 414.0f) {53 return iPhone6Plus; 54} 55} 56 57 return UnKnown; 58} 59 60 @ end

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.