iOS判断设备类型,并设置背景色

- (void)viewDidLoad {

    [super viewDidLoad];

    UIColor *clr = nil;

    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {

        clr = [UIColor colorWithRed:0.875 green:0.88 blue:0.91 alpha:1];

    }else{

        clr = [UIColor groupTableViewBackgroundColor];

    }

    [[self view ] setBackgroundColor:clr];

}

通过UIDevice类发送currentDevice方法,可以得到UIDevice对象,然后检查该对象的userInterfaceIdiom属性。UIUserInterfaceIdiomPad针对Ipad,UIUserInterfaceIdiomPhone针对iphone和ipod touch

你可能感兴趣的:(ios,iPhone,ipad)