根据屏幕尺寸设置UIView高度

时间:2013-03-01 01:10:05

标签: ios xcode uiview screen screen-size

我在桌子下面有一个UIView。 我必须为iPhone 4S或5设置UIView高度。 我尝试使用

- (void) regolaViewPeriPhone {
    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
    {
        CGSize result = [[UIScreen mainScreen] bounds].size;
        if(result.height == 480)
        {
            CGRect frame = CGRectMake(0, 210, 320, 245);
            _pickerContainerView.frame = frame;
        }
        if(result.height == 568)
        {
            CGRect frame = CGRectMake(0, 210, 320, 290);
            _pickerContainerView.frame = frame;
        }
    }
}

但它不起作用,什么是正确的方法?谢谢!

2 个答案:

答案 0 :(得分:1)

[ [ UIScreen mainScreen ] applicationFrame ]

答案 1 :(得分:-2)

这是“根据屏幕尺寸设置UIView高度”的方法

CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (screenBounds.size.height == 568)
{
  //Do u r stuff here for Iphone 5
}
else if(screenBounds.size.height==480)
{
  //Do u r stuff here for Iphone 4s
}

//如果我的回答是正确的,那么请为我投票......

相关问题