5

I want to update my application to ios 6. so how to set the frame size comfortable both iphone 4 and iphone 5?

Ben10
  • 3,221
  • 2
  • 34
  • 61

5 Answers5

4

I can using Calculate the Screen size then to adjust the height of the view like using following method

+(CGFloat)heightOf:(CGFloat)heightValue{
CGRect applicationFrame = [[UIScreen mainScreen] applicationFrame];

//NSLog(@"applciation Frame height = %f",applicationFrame.size.height);
CGFloat heightRatio = (heightValue/480)*100;

CGFloat height = (applicationFrame.size.height * heightRatio)/100;
return height;

}

then I am using like as

UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0,[Height heightOf:385], 320, 220)];

and so. Thanks for your Replies

Ben10
  • 3,221
  • 2
  • 34
  • 61
  • Hi, can you please tell me what is Height in "[Height heightOf:385]". –  Apr 26 '13 at 13:17
3

There is more than one way of handling the situation.

1> One of them is to use auto-resizing properly.

2>Another way is to use the new Auto Layout functionality, but then again this will only be supported for iOS 6.

3>You can create separate nib's for each view one for iphone 4 and iphone 5 and depending on which device it is running, you can switch the used .xib files.

Best way right now to go about is to use, auto resizing properly.

For more you can go through these

1> Supporting iOS 4.3 to iOS 6.0

2> What is the best way for supporting both screen resolution of iPhone4 and iPhone5 ? - Auto layout in only iOS6

Community
  • 1
  • 1
footyapps27
  • 3,982
  • 2
  • 25
  • 42
1

Following code check for the iPhone 5 and other device

#define IS_IPHONE ( [[[UIDevice currentDevice] model] isEqualToString:@"iPhone"] )
#define IS_IPOD   ( [[[UIDevice currentDevice ] model] isEqualToString:@"iPod touch"] )
#define IS_HEIGHT_GTE_568 [[UIScreen mainScreen ] bounds].size.height >= 568.0f
#define IS_IPHONE_5 ( IS_IPHONE && IS_HEIGHT_GTE_568 )

And check for more detail refer the question.

Community
  • 1
  • 1
Nimit Parekh
  • 16,776
  • 8
  • 50
  • 72
0

u can check the device type link or you can check if the view frame larger than the normal one in iPhone 4/4s then resize your frame

note: i'm use the second way and it is work

Omarj
  • 1,151
  • 2
  • 16
  • 43
0

AutoLayout did not work out so well for me. My app has several elements which need to be spaced out evenly.

A Quick fix solution (not good practice) is to assign coordinates individually upon the screen height check. (BTW that is a good tutorial. Shame Apple still haven't come up with anything substantial for IOS).

If You have several element on your screen, then I believe you'll have to re-place them individually

CGFloat height = [UIscreen mainScreen].bounds.size.height;
if(height==568.00){
self.imageName.frame = CGRectMake(x,y,width,height);
...
}

For a modal or floating screen which appears in the center of window, you could try this:

self.imgBadgeArea.frame = CGRectMake(self.view.bounds.size.width/2- self.imgBadgeArea.bounds.size.width/2, self.view.bounds.size.height/2 - self.imgBadgeArea.bounds.size.height/2, self.imgBadgeArea.bounds.size.width, self.imgBadgeArea.bounds.size.height);

Works for both 3.5 and 4 inches.

CalZone
  • 1,701
  • 1
  • 17
  • 29