Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we have the effect of CGRectIntegral on iOS 6 auto-layout generated frames?

Tags:

ios

autolayout

iOS 6 auto layout is pretty handy. However, the auto-generated frames may have non-integral values. How can I force integer output for final frame positions and size using auto layout?

like image 313
lichen19853 Avatar asked Nov 30 '12 22:11

lichen19853


People also ask

What is auto Layout in iOS?

Auto Layout asks your controls how big they need to be and lays out the screen based on that information. Usually, you want to use the intrinsic content size, but there are some cases where you may not want to do that. In these cases, you can set an explicit width or height constraint on a view.

What is the use of auto Layout?

Auto layout is a property you can add to frames and components. It lets you create designs that grow to fill or shrink to fit, and reflow as their contents change. This is great when you need to add new layers, accommodate longer text strings, or maintain alignment as your designs evolve.

What are iOS constraints?

The constraints will make sure that your views adjust to any size changes without having to manually update frames or positions.


1 Answers

AutoLayout is smarter than you think.

While it's true that auto-generated frames can have fractional values, they ARE rounded to match the device's pixel ratio. On devices with Retina display (2x), fractions of 0.5 are allowed. On older devices, there don't seem to be any fractional values at all.

This means that you'll always get a pixel-perfect layout.

Took me quite a while to figure this out though. :)

like image 195
Andreas Ley Avatar answered Nov 04 '22 08:11

Andreas Ley