0

In portrait orientation,I want to layout 4 views horizontally.The 4 views have equal width.Here are the details about every iPhone's width fetched from ios resolution.

iPhone 4/4s/5/5c/5s 's logic resolution width is 320

iPhone 6 's logic resolution width is 375

iPhone 6 plus 's logic resolution width is 414.

So each view's width is going to be:

iPhone 4/4s/5/5c: 320 / 4 = 80(pts)

iPhone 6: 375 / 4 = 93.75(pts)

iPhone 6 plus: 414 / 4 = 103.5(pts)

My question is how does iOS layout system handle these decimals(93.75 & 103.5).And is there any better solution to handle this situation without pixels loss.

Community
  • 1
  • 1
tounaobun
  • 14,570
  • 9
  • 53
  • 75
  • This question might have the answer for you: http://stackoverflow.com/questions/26373598/how-to-create-percentage-of-total-width-using-autolayout [1]: http://stackoverflow.com/questions/26373598/how-to-create-percentage-of-total-width-using-autolayout – mantov1 Jul 02 '15 at 14:44

1 Answers1

2

The SDK does take the scale factor into account when laying out views.

This is why you'll see "integral" frames with fractional values of .5 on a @2x device, or .33 and .66 on a @3x device.

In other words, the layout system will make an effort to align to a device-dependent pixel, even though you constrain in device-independent points.

The best course is to try out a layout and see how it works, as you may discover the SDK already anticipated the situation. Otherwise, you'll be trying to address a non-issue.

In iOS 9, Apple makes this even simpler with UIStackView. You wouldn't need to add any constraints for the views as the stack view would (horizontally) lay them out for you.