【发布时间】:2011-05-26 19:30:21
【问题描述】:
我以编程方式创建了一个 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];
}
//新代码 //INBOX的BEGIN插入按钮//////////////////////////////////// ///////////////
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];
【问题讨论】:
-
放置 appButton = [[UIButton buttonWithType:UIButtonTypeCustom] 保留]; if之前