在我的应用程序(用Objective-C编写)中,如何检测设备是iPhone,iPad还是iPhone5? if([[UIDevice currentDevice]userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { // [iphone] or [itouch]} else { // [ipad]} 您可以在以下条件
if([[UIDevice currentDevice]userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
// [iphone] or [itouch]
} else {
// [ipad]
}
您可以在以下条件下轻松检测iphone,iphone5和iPad(但不是iTouch!iTouch被视为具有此代码的iPhone!): –
if([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPhone)
{
if ([[UIScreen mainScreen] bounds].size.height == 568)
{
}
else
{
//iphone 3.5 inch screen
}
}
else
{
//[ipad]
}
UPDATE
您也可以使用MACRO或定义变量来检查iPhone5,iPhone4或iPad如Bellow: –
#define isiPhone5 ([[UIScreen mainScreen] bounds].size.height == 568)?TRUE:FALSE #define isiPhone (UI_USER_INTERFACE_IDIOM() == 0)?TRUE:FALSE
例:-
if(isiPhone)
{
if (isiPhone5)
{
}
else
{
//iphone 3.5 inch screen
}
}
else
{
//[ipad]
}
