我已经以编程方式创建了一个UIButton,它插在iPhone或iPad上的应用程序中。是否可以为通用应用程序执行此操作(即......更改按钮和位置的大小以适合设备UI)?
//insert button for inbox///////////////////////////////////////////////////////////
appButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
[appButton setBackgroundImage:[UIImage imageNamed:@"18-envelope.png"] forState:UIControlStateNormal];
appButton.layer.borderColor=[UIColor clearColor].CGColor;
appButton.backgroundColor = [UIColor whiteColor];
appButton.frame = CGRectMake(290.0, 25.0, 24.0, 24.0);
[appButton addTarget:self
action:@selector(showAppInbox)
forControlEvents:UIControlEventTouchDown];
[self.window addSubview:appButton];
//END/////////////////////////////////
//Call method to show inbox
-(void) showAppInbox
{
[[AppInboxManager sharedManager] show];
}
//新代码 // BEGIN INBOX的插入按钮/////////////////////////////////////////// ////////////////
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];
答案 0 :(得分:0)
您可以简单地进行以下操作:
if ([[[UIDevice currentDevice] model] isEqualToString: @"iPhone"]){
appButton.frame=XXXX;
}else{
appButton.frame=YYYY;
}
更多信息:
答案 1 :(得分:0)
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
//put your code here
}
else
{
//put your code here
}