views:

39

answers:

1

I've written an application for the iPad that I'd now like to get working on the iPhone (a universal application).

At the moment it runs in the iPhone simulator, but the UIKit elements are positioned using pixel positions - so a lot of them are offscreen. Additionally my UIImages are too big, and need to be scaled to fit the iPhone. How do I go about doing this?

Thanks in advance.

Some more information: If I position a UIImageView using UIBuilder, the image displayed takes up the same ratio of the screen if displayed on the iPad or iPhone. Which is what I want, however I need to do it programatically.

If I create a UIImageView programmatically it will take up a much larger ratio of the screen on the iPhone compared to the iPad.

Edit: My nib is actually empty apart from a OpenGL view. The OpenGL view is scaling fine. I do create a few UIKit controls programmatically and this is where the problem is happening.

+1  A: 

Probably the easiest way: make two separate xibs (1 for iPad, 1 for iPhone). Start a new universal project and migrate the curent one into it, it'll take some time, but it'll save you a lot of headaches.

tadej5553
I set targeted device family to iPhone/iPad so what difference would remaking the project as a universal app make? I've added some more information to my question.
CiscoIPPhone
OK, so in that case, use some kind of macro to differ the behavior between iPhone and iPad. Here's the one I use: #define DEVICE_SPECIFIC_BEHAVIOUR(iPhone, iPad) (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad?(iPad):(iPhone))
tadej5553
Thanks. I still don't know how to handle image sizes. Let's say I want a UIImageView to fill up half the screen, whatever device it is on - how can I do that?
CiscoIPPhone
UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, self.view.frame.size.width, self.view.frame.size.height/2)]
tadej5553
This will fill the screen half in height. Replace self.view with the superiew.
tadej5553
That works - thanks! I didn't realize changing the frame size would change the size of the image (I thought it would clip).
CiscoIPPhone
Changing the size of a UIButton frame doesn't necessarily change the size of the button image, but I've found a solution to that.
CiscoIPPhone
It all depends on contentMode property of UIView. You might wanna take a look at it.
tadej5553