Search code examples
iosxcodeuiviewscreenscreen-size

Set UIView height depending on screen size


I've a UIView under a table. I've got to set UIView height for iPhone 4S or 5. I tried using

- (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;
        }
    }
}

but it doesn't work, what's right method? Thank you!


Solution

  • This is the way to "Set UIView height depending on screen size"

    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
    }
    

    //if my answer is correct then vote up for me...