concept spring in category ios

appears as: springs
iOS Development with Swift

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

Before auto layout, Apple’s first attempt at solving the problem of adaptive layout was called autoresizing, known also as springs and struts. As you’ll see, autoresizing does have limitations compared to auto layout, but can still be a useful tool for quickly building simple interfaces, and the more powerful auto layout can be implemented for more-complex layouts.

  • 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.