Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Layout System Improvements in iOS 9

Layout System Improvements in iOS 9

Presented at potato tips #18

cockscomb

June 16, 2015
Tweet

More Decks by cockscomb

Other Decks in Programming

Transcript

  1. NSLayoutAnchor var leadingAnchor: NSLayoutXAxisAnchor var leftAnchor: NSLayoutXAxisAnchor var centerXAnchor: NSLayoutXAxisAnchor

    var rightAnchor: NSLayoutXAxisAnchor var trailingAnchor: NSLayoutXAxisAnchor var topAnchor: NSLayoutYAxisAnchor var centerYAnchor: NSLayoutYAxisAnchor var bottomAnchor: NSLayoutYAxisAnchor var firstBaselineAnchor: NSLayoutYAxisAnchor var lastBaselineAnchor: NSLayoutYAxisAnchor var widthAnchor: NSLayoutDimension var heightAnchor: NSLayoutDimension
  2. topAnchor │ ▼ ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ ▲ ┃ ┃ │ ┃

    leadingAnchor ┃heightAnchor ┃ trailingAnchor ──▶┃ │ ┃◀── leftAnchor ┃◀────┼──────widthAnchor────▶┃ rightAnchor ┃ │ ┃ ┃ ▼ ┃ ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ ▲ │ bottomAnchor
  3. let imageView = UIImageView() let label = UILabel() NSLayoutConstraint.activateConstraints([ imageView.leadingAnchor

    .constraintEqualToAnchor(label.leadingAnchor), imageView.bottomAnchor .constraintEqualToAnchor(label.topAnchor, constant: 8.0), ]) │╔══════════════════╗ ║ ║ │║ UIImageView ║ ║ ║ │╚══════════════════╝ — │ │8 — │┌─────────────┐ │ UILabel │ │└─────────────┘
  4. UILayoutGuide var leadingAnchor: NSLayoutXAxisAnchor var leftAnchor: NSLayoutXAxisAnchor var centerXAnchor: NSLayoutXAxisAnchor

    var rightAnchor: NSLayoutXAxisAnchor var trailingAnchor: NSLayoutXAxisAnchor var topAnchor: NSLayoutYAxisAnchor var centerYAnchor: NSLayoutYAxisAnchor var bottomAnchor: NSLayoutYAxisAnchor var widthAnchor: NSLayoutDimension var heightAnchor: NSLayoutDimension
  5. let leftLabel = UILabel() let rightLabel = UILabel() let spacer

    = UILayoutGuide() view.addLayoutGuide(spacer) NSLayoutConstraint.activateConstraints([ leftLabel.trailingAnchor .constraintEqualToAnchor(spacer.leadingAnchor), rightLabel.leadingAnchor .constraintEqualToAnchor(spacer.trailingAnchor), leftLabel.widthAnchor .constraintEqualToAnchor(spacer.widthAnchor), leftLabel.widthAnchor .constraintEqualToAnchor(rightLabel.widthAnchor), ]) ┏━━━━━━━━━━━━━┳─────────────┳━━━━━━━━━━━━━┓ ┃ UILabel ┃ Guide ┃ UILabel ┃ ┗━━━━━━━━━━━━━┻─────────────┻━━━━━━━━━━━━━┛ | ─ ─ ─ ─ ─ ─ | ─ ─ ─ ─ ─ ─ | ─ ─ ─ ─ ─ ─ |
  6. UIStackView var axis: UILayoutConstraintAxis // .Horizontal, .Vertical var distribution: UIStackViewDistribution

    // .Fill, .FillEqually, .FillProportionally // .EqualSpacing, .EqualCentering var alignment: UIStackViewAlignment // .Fill, .Leading, .Top, .FirstBaseline // .Center, .Trailing, .Bottom, .LastBaseline var spacing: CGFloat
  7. ─────────────────────────────axis────────────────────────────▶ ╔══════════════════════════════════════════════════════════════╗ ║ ┏━━━━━━━━━━━━━━┓ ┏━━━━━━━━━━━━━━━━━━┓ ┏━━━━━━━━━━━━━━┓ ║ ║ ┃ —

    ┃ ┃ ┃ ┃ ┃ ║ ║ ┃ │ ┃ ┃ spacing ┃ ║ ║ ┃ │ ┃ ┃ ┃|──|┃ ┃ ║ ║ ┃ │ ┃ ┃ ┃ ┃ ┃ ║ ║ ┃ alignment ┃ ┃ ┃ ┗━━━━━━━━━━━━━━┛ ║ ║ ┃ │ ┃ ┃ ┃ ║ ║ ┃ │ ┃ ┃|──distribution──|┃ ║ ║ ┃ │ ┃ ┃ ┃ ║ ║ ┃ — ┃ ┃ ┃ ║ ║ ┗━━━━━━━━━━━━━━┛ ┃ ┃ ║ ║ ┃ ┃ ║ ║ ┃ ┃ ║ ║ ┗━━━━━━━━━━━━━━━━━━┛ ║ ╚══════════════════════════════════════════════════════════════╝
  8. New Layout Systems • New classes • NSLayoutAnchor • UILayoutGuide

    • UIStackView • Great improvements for iOS (OS X)
  9. !