Detect iOS device type

前端 未结 5 2028
感动是毒
感动是毒 2020-11-29 04:16

In my application (written in Objective-C), how do I detect if the device is an iPhone, iPad, or iPhone5?

if([[UIDevice currentDevice]userInterfaceIdiom] ==          


        
5条回答
  •  伪装坚强ぢ
    2020-11-29 04:54

    - (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle {
    if ([[ UIScreen mainScreen ] bounds ].size.height == 568 ) {
    nibName = [NSString stringWithFormat:@"%@_568", nibName];
    
    }
    
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    nibName = [NSString stringWithFormat:@"%@_iPad", nibName]; {
    
    }
    
    if (self = [super initWithNibName:nibName bundle:nibBundle]) {
    }
    
    return self;
    }
    

    The first statement checks weather the device you have has the iPhone 5 Screen.

    The Second checks weather you're using a iPad.

    The third returns the normal xib for the iPhone 4s and prior.

    Please note, to make this work you'll have to create 3 different XIB's, all with a different suffix.

    ViewController.xib

    ViewController_568.xib

    ViewController_iPad.xib

提交回复
热议问题