concept margin in category ios

appears as: margin, margins, margins
iOS Development with Swift

This is an excerpt from Manning's book iOS Development with Swift.

  • Add the following line where you set up the redView in the viewDidLoad method:
    redView.autoresizingMask = [.flexibleHeight, .flexibleWidth,
       .flexibleBottomMargin]
    Follow the same process for the label described in table 6.4.
    Table 6.4. Label

    Attribute

    Description

    Left margin 20
    Width Fixed width
    Right margin Width of superview (minus) width (minus) left margin
    Top margin Half the height of the superview
    Height Fixed height
    Bottom margin Superview height (minus) height (minus) top margin
    In the label’s case, the right margin, top margin, and bottom margin are all relative to the superview, so you should set them to springs.
  • Give the outer stack view fixed margins by selecting Fixed in the Layout Margins section of the Size Inspector, with margins of 16 all round. The stack view should now be nicely framed in the scroll view (see figure 8.10). You can take advantage of the scroll view’s ability to dismiss the keyboard.