Thursday, April 14, 2016

UIViewAutoresizingMask basics



As for me autoresizing is technology from the past, new AutoLayout fully replaced it, but sometimes using Autoresizing easier that AutoLayout. In this small article you can read about setting UIViewAutoresizing programmatically.



Horizontally:
  • Resize keeping fixed left/right margins: UIViewAutoresizingFlexibleWidth
  • Keep size and same distance from the left: UIViewAutoresizingFlexibleRightMargin
  • Keep size, stay centered: UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin
  • Keep size and same distance from the right: UIViewAutoresizingFlexibleLeftMargin

Vertically:
  • Resize keeping fixed top/bottom margins: UIViewAutoresizingFlexibleHeight
  • Keep size and same distance from the top: UIViewAutoresizingFlexibleBottomMargin
  • Keep size, stay centered: UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin
  • Keep size and same distance from the bottom: UIViewAutoresizingFlexibleTopMargin

Combine one from the first section with one from the second with a  | . For example, to have it resize horizontally and keep the same size and distance from the top vertically, you'd use UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin.

Source

No comments:

Post a Comment