在Xcode 5.0.1(更新的xcode 6)中为3.5,4.0(更新的4.7和5.5)英寸屏幕开发相同的UI,没有风景,没有iPad,没有故事板

问题描述 投票:8回答:5
  1. 我开发的应用程序考虑3.5英寸与.xib文件而不是故事板。
  2. 我无法找到任何教程或指南,这将有助于我设计类似于所有屏幕的应用程序。
  3. 我正在使用Xcode 5.0.1
  4. 我只开发没有自动布局的普通应用程序,仅适用于iOS 6和iOS 7(IPhone)。
  5. 下面是截图在不同屏幕上的不同之处。 A. IPhone iOS 6模拟器: B. 3.5英寸(Ios 6和Ios 7)C。4.0英寸(Ios 6和Ios 7)

更新:请更新以下答案,也知道4.7和5.5英寸的屏幕。

iphone ios7 ios6 xib
5个回答
15
投票

如果你想以编程方式检查它:

对于斯威夫特

extension UIDevice {

 var iPhoneX: Bool {
    return UIScreen.main.nativeBounds.height == 2436
 }
 var iPhone: Bool {
    return UIDevice.current.userInterfaceIdiom == .phone
 }
 enum ScreenType: String {
    case iPhone4_4S = "iPhone 4 or iPhone 4S"
    case iPhones_5_5s_5c_SE = "iPhone 5, iPhone 5s, iPhone 5c or iPhone SE"
    case iPhones_6_6s_7_8 = "iPhone 6, iPhone 6S, iPhone 7 or iPhone 8"
    case iPhones_6Plus_6sPlus_7Plus_8Plus = "iPhone 6 Plus, iPhone 6S Plus, iPhone 7 Plus or iPhone 8 Plus"
    case iPhoneXR = "iPhone XR"
    case iPhoneX_iPhoneXS = "iPhone X,iPhoneXS"
    case iPhoneXSMax = "iPhoneXS Max"
    case unknown
 }

 var screenType: ScreenType {
    switch UIScreen.main.nativeBounds.height {
    case 960:
        return .iPhone4_4S
    case 1136:
        return .iPhones_5_5s_5c_SE
    case 1334:
        return .iPhones_6_6s_7_8
    case 1792:
        return .iPhoneXR
    case 1920, 2208:
        return .iPhones_6Plus_6sPlus_7Plus_8Plus
    case 2436:
        return .iPhoneX_iPhoneXS
    case 2688:
        return .iPhoneXSMax
    default:
        return .unknown
    }
  }
}

您可以检查:

print("screenType:", UIDevice.current.screenType.rawValue)

用于检查Retina(3.5 / 4英寸屏幕)或非视网膜

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
}

更新:

用于以编程方式检查所有视网膜iPhone:

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)
      }
 }

还检查一下

#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)

它可以帮到你。

快乐的编码。


7
投票

将下面的行放在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))))

现在编程你可以说......

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");
}

2
投票

您可以使用自动布局或代码。在代码中,您可以使用layoutSubviews方法。只需检查视图高度即可发现iPhone 3.5或4英寸并进行设置:

-(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
    }
}

1
投票

迅速:

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
    }

0
投票

你也可以全局定义。

#define isIPHONE5 ([UIScreen mainScreen].bounds.size.height == 568.f)
if(isIPHONE5){

// iphone 5 screen

}else{

// iphone 3.5 screen

}
© www.soinside.com 2019 - 2024. All rights reserved.