1

I have 2 storyboards one is for an iPhone 5 and the other for the 4s/4/3. I made my picker programmitcally and I positioned it accordingly so it fits on the iphone 5 with this code

 picker1 = [[UIPickerView alloc] initWithFrame:CGRectMake(13, 272.5, 294, 219
                                                        )];

etc.

But when I run it on my iPhone 4 it is too low and I dont want to ruin my iphone 5 since Ive spent the last two days perfect everything on it. Is there a way to have the iphone load the same picker but at different sizes and coordinates based on the screen size for instance if screen == 568 ..... else ....

?? This is the last step in my app. Any clue how to complete this ?

Gabriel
  • 328
  • 5
  • 16

1 Answers1

2

This should provide what you're after:

CGRect iphone5frame = CGRectMake(13, 272.5, 294, 219);
CGRect iphone4frame = CGRectMake(13, 272.5, 294, 219); // Edit these values for the iPhone 4
picker1 = [[UIPickerView alloc] initWithFrame:([[UIScreen mainScreen] bounds].size.height <= 480.0 ? iphone4frame : iphone5frame)];

EDIT: Updated code for more customization

zachjs
  • 1,738
  • 1
  • 11
  • 22
  • so i would basically just copy my picker1 = [[UIPickerView alloc] initWithFrame:CGRectMake(13, 272.5, 294, 219 )]; where you put the ( ) and make it fit the iphone 4? – Gabriel Oct 08 '12 at 04:51
  • You would replace the line you posted with the lines I provided and replace the `(whatever you want on the non-iPhone 5 display)` with a proper number suited for an iPhone 4S/4/3/etc display. If this works for you please mark the answer as accepted. – zachjs Oct 08 '12 at 04:56
  • to be honest i'm a bit lost on what goes after the int retina35= ? so for example i'd put int retina35 = (13,272.5,294,219); that would be the size and position of the picker on the iPhone4? – Gabriel Oct 08 '12 at 06:16
  • The variable `retina40` contains the `y` location you would like your UIPickerView to be at on the iPhone 5. The variable `retina35` should contain the same value except targeted for the iPhone 4S/4/3/etc. – zachjs Oct 08 '12 at 06:19
  • it works. I just had one question more. Can i change the size of the picker on the iphone 4 and keep the size on the iphone 5 the same as it was. It is too big on the 4 and perfect on the 5 – Gabriel Oct 08 '12 at 06:23
  • would it just be adding more variables in the 'retina35' – Gabriel Oct 08 '12 at 06:24
  • I updated my answer to allow full customization of both frames. – zachjs Oct 08 '12 at 06:27
  • THANK YOU SO MUCH YOU ARE A LIFE SAVER! Everything works. You sir just helped me complete my first app. thanks – Gabriel Oct 08 '12 at 06:34