- I have developed app considering 3.5 inch with .xib files and not storyboard.
- I am unable to find any tutorial or guide which will help me in designing app similar for all screens.
- I am using Xcode 5.0.1
- I am developing only plain app with no auto layout and only for iOS 6 and iOS 7 (IPhone).
Below is the screenshot how it differs on different screens.
A. IPhone iOS 6 simulator:
B. 3.5 Inch (Ios 6 and Ios 7)
C. 4.0 Inch (Ios 6 and Ios 7)
Update:
Please update below answers to also know 4.7 and 5.5 inches screen.
If you want check it Programmatically :
For checking Retina (3.5/4 inch Screen) or Non-Retina
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
if ([[UIScreen mainScreen] scale] == 2.0) {
if([UIScreen mainScreen].bounds.size.height == 568){
// iPhone retina-4 inch
} else{
// iPhone retina-3.5 inch
}
}
else {
// not retina display
}
Update:
checking ios8 or ios 7
NSOperatingSystemVersion ios8_0_0 = (NSOperatingSystemVersion){8, 0, 0};
if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:ios8_0_0]) {
// iOS 8 stuff
} else {
// iOS 7 and below stuff
}
For checking All retina iPhone Programmatically:
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
if ([[UIScreen mainScreen] scale] == 2.0) {
if([UIScreen mainScreen].bounds.size.height == 667){
// iPhone retina-4.7 inch(iPhone 6)
}
else if([UIScreen mainScreen].bounds.size.height == 568){
// iPhone retina-4 inch(iPhone 5 or 5s)
}
else{
// iPhone retina-3.5 inch(iPhone 4s)
}
}
else if ([[UIScreen mainScreen] scale] == 3.0)
{
//if you want to detect the iPhone 6+ only
if([UIScreen mainScreen].bounds.size.height == 736.0){
//iPhone retina-5.5 inch screen(iPhone 6 plus)
}
//iPhone retina-5.5 inch screen(iPhone 6 plus)
}
}
Also check this
#define IS_IPHONE_5 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 568.0)
#define IS_IPHONE_6 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 667.0)
#define IS_IPHONE_6_PLUS (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 736.0)
FOR Swift 3.0
if UIDevice().userInterfaceIdiom == .Phone {
switch UIScreen.mainScreen().nativeBounds.height {
case 480:
print("iPhone Classic")
case 960:
print("iPhone 4 or 4S")
case 1136:
print("iPhone 5 or 5S or 5C")
case 1334:
print("iPhone 6 or 6S or 7")
case 1920:
print("iPhone 6+ or 6S+ or 7+")
default:
print("unknown")
}
}
You can also extend UIDevice as follow:
extension UIDevice {
var iPhone: Bool {
return UIDevice().userInterfaceIdiom == .Phone
}
enum ScreenType: String {
case iPhone4
case iPhone5
case iPhone6/iPhone7
case iPhone6Plus/iPhone6splus/iPhone7plus
case unknown
}
var screenType: ScreenType {
guard iPhone else { return .unknown }
switch UIScreen.mainScreen().nativeBounds.height {
case 960:
return .iPhone4
case 1136:
return .iPhone5
case 1334:
return .iPhone6/iPhone7
case 1920:
return .iPhone6Plus/iPhone6splus/iPhone7plus
default:
return .unknown
}
}
}
edit/update
Xcode 8.1 • Swift 3.0.1
extension UIDevice {
var iPhone: Bool {
return UIDevice().userInterfaceIdiom == .phone
}
enum ScreenType: String {
case iPhone4
case iPhone5
case iPhone6/iPhone7
case iPhone6Plus/iPhone6splus/iPhone7plus
case unknown
}
var screenType: ScreenType {
guard iPhone else { return .unknown }
switch UIScreen.main.nativeBounds.height {
case 960:
return .iPhone4
case 1136:
return .iPhone5
case 1334:
return .iPhone6/iPhone7
case 1920:
return .iPhone6Plus/iPhone6splus/iPhone7plus
default:
return .unknown
}
}
}
may it will help you .
Happy coding.
Put below lines in prefix.pch
#define IS_DEVICE_RUNNING_IOS_7_AND_ABOVE() ([[[UIDevice currentDevice] systemVersion] compare:@"7.0" options:NSNumericSearch] != NSOrderedAscending)
#define iPhoneVersion ([[UIScreen mainScreen] bounds].size.height == 568 ? 5 : ([[UIScreen mainScreen] bounds].size.height == 480 ? 4 : ([[UIScreen mainScreen] bounds].size.height == 667 ? 6 : ([[UIScreen mainScreen] bounds].size.height == 736 ? 61 : 999))))
Now in programming you can say...
if (IS_DEVICE_RUNNING_IOS_7_AND_ABOVE()) {
NSLog("This is iOS 7");
} else {
NSLog("This is iOS 6 or below");
}
if (iPhoneVersion==4) {
NSLog("This is 3.5 inch iPhone - iPhone 4s or below");
} else if (iPhoneVersion==5) {
NSLog("This is 4 inch iPhone - iPhone 5 family");
} else if (iPhoneVersion==6) {
NSLog("This is 4.7 inch iPhone - iPhone 6");
} else if (iPhoneVersion==61) {
NSLog("This is 5.5 inch iPhone - iPhone 6 Plus.. The BIGGER");
} else {
NSLog("This is iPad");
}
You can use auto layout or code. In code you can use layoutSubviews method. Just check view height to discover is it a iPhone 3.5 or 4 inch and do your set up:
-(void)layoutSubviews
{
if (self.view.bounds.size.height == 568)
{
[self.textField setFrame:CGRectMake(0, 0, 100, 30)];
//... other setting for iPhone 4inch
}
else
{
[self.textField setFrame:CGRectMake(0, 0, 100, 30)];
//... other setting for iPhone 3.5 inch
}
}
SWIFT:
if(DeviceType.IS_IPHONE_4_OR_LESS)
{
//DO THIS
}
//*********************************************************************
enum UIUserInterfaceIdiom : Int
{
case Unspecified
case Phone
case Pad
}
struct ScreenSize
{
static let SCREEN_WIDTH = UIScreen.mainScreen().bounds.size.width
static let SCREEN_HEIGHT = UIScreen.mainScreen().bounds.size.height
static let SCREEN_MAX_LENGTH = max(ScreenSize.SCREEN_WIDTH, ScreenSize.SCREEN_HEIGHT)
static let SCREEN_MIN_LENGTH = min(ScreenSize.SCREEN_WIDTH, ScreenSize.SCREEN_HEIGHT)
}
struct DeviceType
{
static let IS_IPHONE_4_OR_LESS = UIDevice.currentDevice().userInterfaceIdiom == .Phone && ScreenSize.SCREEN_MAX_LENGTH < 568.0
static let IS_IPHONE_5 = UIDevice.currentDevice().userInterfaceIdiom == .Phone && ScreenSize.SCREEN_MAX_LENGTH == 568.0
static let IS_IPHONE_6 = UIDevice.currentDevice().userInterfaceIdiom == .Phone && ScreenSize.SCREEN_MAX_LENGTH == 667.0
static let IS_IPHONE_6P = UIDevice.currentDevice().userInterfaceIdiom == .Phone && ScreenSize.SCREEN_MAX_LENGTH == 736.0
static let IS_IPAD = UIDevice.currentDevice().userInterfaceIdiom == .Pad && ScreenSize.SCREEN_MAX_LENGTH == 1024.0
}
you can also define globally.
#define isIPHONE5 ([UIScreen mainScreen].bounds.size.height == 568.f)
if(isIPHONE5){
// iphone 5 screen
}else{
// iphone 3.5 screen
}