0

Now I'm trying to make my app compatible for iPhone 6/6+. The issue is, I have 4 buttons horizontally aligned in one row. The width of each of them is 80 points(set in the storyboard). It's fine for iPhone4/5/5s. Now when I simulated the app on iPhone 6/6+, you can see there's 2 pixels space between the 3rd and 4th buttons. I'm not using auto layout. I know the width of iPhone 6 plus is: 1242 x 2208px. The problem is 1242 cannot be divided by 4.

enter image description here

The issue is when I use following code:

CGRect screenBounds = [[UIScreen mainScreen] bounds];
CGFloat screenScale = [[UIScreen mainScreen] scale];
CGSize screenSize = CGSizeMake(screenBounds.size.width * screenScale, screenBounds.size.height * screenScale);
CGFloat screenWidth = screenSize.width;

Actually the screenWidth is 640.

Anybody know how to sort out this problem? Many thanks in advance.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Vigor
  • 1,706
  • 3
  • 26
  • 47

1 Answers1

2

You should be working in points, not pixels, so the iPhone 6 Plus has a width (when in portrait mode) of 414, and the iPhone 6 is 375.

When dividing up the screen in this situation, i.e., where the math doesn't work out exactly, you'll want to ensure the smallest spaces are equal (so the dividers in this case), and make the large areas slightly different sizes (off by a point etc). This is because (usually) the eye will be able to notice the difference between 1 and 2 points, but not a difference between say 102 and 103 points.

You may want to look at setting up this view with Auto Layout though instead of doing the math yourself. This is what's it's made for.

Regarding your second point about the variable screenWidth being 640, make sure your app isn't in compatibility mode. If it is, the 6 and 6+ with both return dimensions as if they're a 5s, and that would explain the 640 number. Add a LaunchScreen.xib to ensure your app runs at the true screen resolution instead of scaling. See here: How to enable native resolution for apps on iPhone 6 and 6 Plus?

Community
  • 1
  • 1
Dave Wood
  • 13,143
  • 2
  • 59
  • 67
  • thank you @Dave Wood for your response. The issue I don't want to use autolayout is I have about 30 screens in the storyboard. Once I set one ViewController autolayout, all of the ViewControllers in the storyboard will be set auto layout automatically. And their layout will be messed up. I really want a quick fix, and later will change the storyboard to autolayout. Is there a way to only set One ViewController as autolayout, and the others kept the original setting? – Vigor Feb 02 '15 at 06:23
  • You should be able to select just one view and change that to "Use Auto Layout" (in the File Inspector in the IB view). It should only affect it's subviews. It's great to learn by just using it for one view at a time (not even a whole View Controller). – Dave Wood Feb 02 '15 at 06:30