Search code examples
storyboardios6uipickerviewiphone-5

2 Storyboards and 1 PickerView


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 ?


Solution

  • 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