我正在尝试根据 iphone 5 屏幕尺寸定位 uicontrols。因此我已相应地设置了背景图像。但我不确定如何定位 uicontrols。
请告诉我
UIImage* myImage;
CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
if ([UIScreen mainScreen].scale == 2.f && screenHeight == 568.0f) {
myImage = [UIImage imageNamed:@"bg-for5-568h.png"];
} else {
myImage = [UIImage imageNamed:@"bg.png"];
}
self.view.backgroundColor = [UIColor colorWithPatternImage:myImage];
self.view.autoresizesSubviews = YES;
self.navigationController.navigationBarHidden = YES;
// Create an UIButton
UIButton *aCalculateBtn = [UIButton buttonWithType: UIButtonTypeCustom];
UIImage *imgBack = [[UIImage imageNamed:@"calc.png"]
stretchableImageWithLeftCapWidth:22
topCapHeight:0];
[aCalculateBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
aCalculateBtn.titleLabel.font = [UIFont boldSystemFontOfSize:14.0];
aCalculateBtn.titleLabel.shadowOffset = CGSizeMake(0, -1);
[aCalculateBtn setBackgroundImage:imgBack forState:UIControlStateNormal];
[aCalculateBtn addTarget:self action:@selector(showQuestions) forControlEvents:UIControlEventTouchUpInside];
aCalculateBtn.frame = CGRectMake(150,160, 150, 38);
aCalculateBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
aCalculateBtn.bounds = CGRectInset(aCalculateBtn.bounds, -3, 1);
[self.view addSubview:aCalculateBtn];
// Create an UIButton
UIButton *anAboutBtn = [UIButton buttonWithType: UIButtonTypeCustom];
UIImage *imgAbout = [[UIImage imageNamed:@"about-us.png"]stretchableImageWithLeftCapWidth:22 topCapHeight:0];
[anAboutBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
anAboutBtn.titleLabel.font = [UIFont boldSystemFontOfSize:14.0];
anAboutBtn.titleLabel.shadowOffset = CGSizeMake(0, -1);
[anAboutBtn setBackgroundImage:imgAbout forState:UIControlStateNormal];
[anAboutBtn addTarget:self action:@selector(showAbout)
forControlEvents:UIControlEventTouchUpInside];
anAboutBtn.frame = CGRectMake(150,190, 150, 38);
anAboutBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
anAboutBtn.bounds = CGRectInset(anAboutBtn.bounds, -3, 1);
[self.view addSubview:anAboutBtn];