Ios4 基于设备的UIButton编程

Ios4 基于设备的UIButton编程,ios4,xcode4,uibutton,ipad,Ios4,Xcode4,Uibutton,Ipad,我以编程方式创建了一个UIButton,它可以插入到iPhone或仅iPad的应用程序中。是否可以为通用应用程序执行此操作(即…更改按钮大小和位置以适应设备UI) //新代码 //收件箱的开始插入按钮/////////////////////////////////////////////////////////// if ([[[UIDevice currentDevice] model] isEqualToString:@"iPhone"]) { appButto

我以编程方式创建了一个UIButton,它可以插入到iPhone或仅iPad的应用程序中。是否可以为通用应用程序执行此操作(即…更改按钮大小和位置以适应设备UI)

//新代码 //收件箱的开始插入按钮///////////////////////////////////////////////////////////

   if ([[[UIDevice currentDevice] model] isEqualToString:@"iPhone"])

    {


    appButton.frame = CGRectMake(200, 25, 24, 16);



   }

    else

    {

    appButton.frame = CGRectMake(700, 25, 24, 16);


    }

    appButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];

    [appButton setBackgroundImage:[UIImage imageNamed:@"envelope_white.png"] forState:UIControlStateNormal];
    appButton.layer.borderColor=[UIColor clearColor].CGColor;
    appButton.backgroundColor = [UIColor clearColor];



    [appButton addTarget:self
                      action:@selector(showAppInbox)
            forControlEvents:UIControlEventTouchDown];  

您可以简单地执行以下操作:

if ([[[UIDevice currentDevice] model] isEqualToString: @"iPhone"]){


      appButton.frame=XXXX;

}else{

      appButton.frame=YYYY;

}
 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
//put your code here
}

else

{
//put your code here
}
更多信息请访问:


@Saimonx谢谢你把我推向了正确的方向。我找到了答案,并使用以下方法完成:

if ([[[UIDevice currentDevice] model] isEqualToString: @"iPhone"]){


      appButton.frame=XXXX;

}else{

      appButton.frame=YYYY;

}
 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
//put your code here
}

else

{
//put your code here
}

感谢Saimonx…我确实有一个错误…“预期”]“在if语句行中,您缺少一个“:”在isEqualToString之后。现在,由于某种原因,我的iPhone上的按钮不见了,但它是我在iPadsorry上为以下内容指定的”:,请显示您正在使用的代码。它看起来像是直接跳到else语句。请放置一个NSLog(@“Model:%s”,[[UIDevice currentDevice]Model]);对于iPhone,可能是“iPhone操作系统”,或者类似的东西,而不是“iPhone”放置appButton=[[UIButton Button WithType:UIButtonTypeCustom]retain];在国际单项体育联合会之前