1
votes

I know iphone 5 size is 640*960 and iphone 4 and previous iphone size is 320*480. Right now, I am confused. If I want my app working on these different iphones, how to calculate the frame for a imageview or button. For example in viewDidLoad, I have a image and it's size are 630*100 with name of [email protected], another size is 315*50 with name of someImage.png. The images are the same but the size is different. and then I created a UIImageView with frame of CGRectMake(5, 5, 315, 50), that's for 320*480 size. Do I have to do if (iphone5) then set another frame for UIImageView with frame of CGRectMake(10, 10, 630, 100)? Do I have to prepare two different UIImageView frames for these 2 kinds of size?

4
No, but this has been asked many, many times. CoreGraphics works with points, not with pixels.user529758
then How do I set the point when I just have size with pixels?yong ho
You don't give a damn about sizes and CG will figure it out for you automagically. But this has been answered many, many times.user529758

4 Answers

5
votes

All coordinates and sizes on iOS use points rather than pixels. 1 point on the normal iPhone screen (320x480) equals 1 pixel. 1 point on the Retina iPhone screen (640x960) equals 2 pixels.

So CGRectMake(5, 5, 315, 50) automatically translates to x = 10, y = 10, width = 630, height = 100 on the Retina screens.

1
votes

CGRect work on Points not the Pixels so there is no width diffrence in iPhone4 and iPhone5

if you use [[UIScreen mainScreen]applicationFrame].size.width you get 320 width for both device.

0
votes

why not use img.size

just like this:

UIImage *img = [UIImage imageNamed:@"yourImage"];
CGRect * rect = CGRectMake(5, 5, img.size.width,img.size.height);
-3
votes
 Uiscrolview *myScrolView= [[Uiscrolview alloc] initWithFrame:CGRectMake(self.view.frame.origin.x+50,self.view.frame.origin.x+50, self.view.frame.size.width-100, self.view.frame.size.height-300);