0

I am new to iPhone development i want to make my code compatible with iPhone 4s and iPhone5
but when i apply image to background view of 4S its size 320*480 but it changes in iPhone 5. How to manage this compatibility? Also do i need manage compatibility for buttons and their position in iPhone 4s and iPhone 5. If yes? then how to handle position of button pro-grammatically...

I found this solution ..

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480)
{
    // iPhone Classic    }
if(result.height == 568)
{
    // iPhone 5
}}

Does it works?

1 Answers1

0

Yes, you are doing it in correct way.

Now, what you need to do is, you just need check the condition and based on that, you have to set the Frame of the components on the screen.

if([UIScreen mainScreen].bounds.size.height == 568)
{
    // iPhone 5  
     // Set the frame of the buttons for iPhone5 screen
}
else
{
    // iPhone 4
     // Set the frame of the buttons for iPhone4 & 4S screen
}
}
Ajay Sharma
  • 4,509
  • 3
  • 29
  • 59
  • means we have to for all button and all Image view is this is a standard way or not??? – user2248322 Apr 05 '13 at 10:15
  • ohhh Yes ... nothing wrong it.I am doing this in most of ma apps.For further you can check if this could help you : http://stackoverflow.com/a/12397309/434898 – Ajay Sharma Apr 05 '13 at 10:19
  • thank you....does it run only in device??? since we try to run it in simulator of 320*480 so its executing only one condition ...... – user2248322 Apr 05 '13 at 12:51
  • Nopes .that do work in Simulator too.But you need to switch your Simulator accordingly. – Ajay Sharma Apr 05 '13 at 18:11
  • how to switch our simulator we ^ahve tried using retina 3.5 diasplay and all but its not showing – user2248322 Apr 08 '13 at 05:15
  • you can change your simulator from iOS Simulator-> Hardware->Device-> iPhone (3.5 Retina)/iPhone (4 Retina). similarly with simulator version. – Ajay Sharma Apr 08 '13 at 08:54
  • thanks i got it. if i want to apply background image to view should i need two differrent images i.e one for iPhonr 4s and other for iPhone 5 ....also let me know what autolayout in ios 6 i am not getting – user2248322 Apr 08 '13 at 09:39
  • @user2248322 simply you can use : self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"screen_background.png"]]; or depend on the artwork your image got in background. – Ajay Sharma Apr 08 '13 at 10:02