2013-02-19 28 views
0

我想根據iphone 5的屏幕尺寸來定位uicontrols。但我已經相應地設置了背景圖像。但我不知道如何定位uicontrols。如何根據iPhone 5屏幕定位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]; 
+0

你想完成什麼?我們無法讀懂你的想法。看看[這個問題](http://stackoverflow.com/questions/12395200/how-to-develop-or-migrate-apps-for-iphone-5-screen-resolution/)的一些提示,並嘗試讓你的問題更具體。 – 2013-02-19 07:55:40

回答

0

你有2個選擇,你既可以使用自動佈局與佈局約束在這裏閱讀:

http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/AutolayoutPG/Articles/adoption.html

您需要更改或者view.frame。基於這種屏幕高度的每個版本的原點或view.frame.center。

if([ [ UIScreen mainScreen ] bounds ].size.height == 568) 
{ 
    self.view.frame = CGRectMake(0,0,320,568); 
    self.view.center = CGPointMake(284); 

} 
else 
{ 
    self.view.frame = CGRectMake(0,0,320,480); 
    self.view.center = CGPointMake(160,240); 
}