Autolayout notes

Notes on using AutoLayout


When using AutoLayout in building iOS applications, use container views and temporarily set their background color to something visiible. Here is an example of laying out two "sections" of the screen proportionally without using vertical stack views. First screenshot below is the view hierarchy:


Next screenshot shows the Main storyboard:


Next up are the superview constraints:


The explanation of some constraints follows:
  1. ButtonsView.top = PictureView.bottom+2
    gives a gap of 2 points between the ButtonsView top and PictureView bottom
  2. bottom = ButtonsView.bottom constrains the bottom of the ButtonsView to "hug" the bottom of the topmost view
Here are the ButtonsView constraints:


  1. The height of the ButtonsView is constrained to 100 so that the PictureView can take up the remaining space.
  2. The buttons stackview is constrained to be centered vertically and horizontally within the ButtonsView.
Here are the PictureView constraints:


  1. Image top is set 10 points away from the "Guess the Animal" label
  2. bottom of the containing PictureView is pinned to the bottom of the image view.
  3. "Guess the animal" label is 10 points from the top of the PictureView
  4. "Guess the animal" label is centered horizontally within the PictureView
Here are the StackView constraints:


  1. Stack View is constrained to height 100
  2. Stack View is horizontally and vertically centered inside its containing view.

Comments

Popular posts from this blog

QTreeView and QTableView dynamic changes

C++ strings and string_view