0

Right now I have 2 view controllers in my app. They both use UIViews and UIButtons, and I have gone to the Size Inspector in the Storyboard and changed their width and height values, and for some I have even changed the X and Y values.

Everything looks perfect on my iPhone 4s, but I just realized that these values I have set might not be correct for other devices like the iPhone 3 or iPhone 5 models.

Here's an example of the values I have added for one of my UIViews:

  1. X: 0
  2. Y: 0
  3. Width: 320
  4. Height: 568

Here's an example of the values I have added for one of my UIButtons that I wanted to perfectly center in the middle of the screen:

  1. X: 139
  2. Y: 224
  3. Width: 41
  4. Height: 30

Do I have anything to worry about in terms of these storyboard elements looking distorted or being misplaced and in the wrong part of the screen on different iPhone models? Should I be doing something differently like creating them programmatically?

I just want to make sure that what looks correct for my iPhone won't look terrible on a user's iPhone when the app is released, and I won't have access to any different iPhone models until a week from now.

Thanks for the help.

user3344977
  • 3,584
  • 4
  • 32
  • 88

3 Answers3

1

This is what auto layouts was made for. I won't go into detail about it since there are a lot of other posts and sources of info on it, but you would be able to easily always have your button centered, regardless of screen size. You'd also be able to do all of this in interface builder. Here's a good start if you haven't read up on it yet: http://www.raywenderlich.com/50317/beginning-auto-layout-tutorial-in-ios-7-part-1

JJC
  • 1,346
  • 10
  • 10
1

Another option, easier to understand than Autolayout, is the Auto-resizing mask, also known as "struts and springs":

You can set the Auto-resizing mask in Interface Builder or in code (see the autoresizingMask property of your components): Autoresizing masks programmatically vs Interface Builder / xib / nib

While struts and springs aren't as powerful as Autolayout, they suit the needs for the majority of cases. I've got three apps in the app store and haven't needed Autolayout yet.

To use "struts and springs", simply turn Autolayout off.

Community
  • 1
  • 1
Marcus Adams
  • 53,009
  • 9
  • 91
  • 143
0

If your autolayout properties are set well, you're probably fine. If you'd like to do it programmatically, you could use things like this: (to place button in center)

customButton.center = customView.center;

If you want something to be the size of the screen, do something like this

customView.bounds = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height;
Logan
  • 52,262
  • 20
  • 99
  • 128
  • Autolayout should work for now, but i might have to implement this once I test on different models later this week. Thanks for the help. – user3344977 Mar 13 '14 at 20:05
  • Ya, if you're setting up autolayout well, it should be fine! I just have a personal preference to code! Good luck. – Logan Mar 13 '14 at 20:06