简体   繁体   中英

UIView for iphone5 and iphone4

I have created a UIView , with two xibs to support to iphone5 and iphone4. The view width is (iphone5 - 470) and (iphone5 - 400). I have initialized this view with checking the conditions for iphone5 or iphone4. But while running the app, it seems to take the iphone5.

CategoryView *puzzleView = [[CategoryView alloc] initWithFrame:CGRectMake(0, startY, levelScrollView.frame.size.width, 190)];
BOOL isiPhone = IS_IPHONE5([[UIScreen mainScreen] bounds].size.height);
if (isiPhone)
{
    puzzleView = [[[NSBundle mainBundle] loadNibNamed: @"CategoryView5"  owner:self options:nil] objectAtIndex:0];
}
else 
{
    puzzleView = [[[NSBundle mainBundle] loadNibNamed: @"CategoryView-iphone"  owner:self options:nil] objectAtIndex:0];
}

The probles lies in this line:

BOOL isiPhone = IS_IPHONE5([[UIScreen mainScreen] bounds].size.height);

No you are just checking wether the size.height is not 0

Change into something like :

BOOL isiPhone = IS_IPHONE5([[UIScreen mainScreen] bounds].size.height > 480.f);

Bout one should not do it like this. Just make one view and let it grow with the screen size is a better option. Just incase Apple ever decide to add an other screen size you will not have to change anything in your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM