In iOS 8 Apple introduced layout margins to UIKit, as a way to streamline view alignment easily even for most complex layouts. In this talk I share insights about layout margins and concepts around them.
var layoutMargins: UIEdgeInsets @available(iOS 11.0, *) open var directionalLayoutMargins: NSDirectionalEdgeInsets } public struct NSDirectionalEdgeInsets { public var top: CGFloat public var leading: CGFloat public var bottom: CGFloat public var trailing: CGFloat } public struct UIEdgeInsets { public var top: CGFloat public var left: CGFloat public var bottom: CGFloat public var right: CGFloat }
open var layoutMarginsGuide: UILayoutGuide { get } } self.layoutMarginsGuide.leadingAnchor self.layoutMarginsGuide.trailingAnchor self.layoutMarginsGuide.topAnchor self.layoutMarginsGuide.bottomAnchor self.layoutMarginsGuide.width …
open var readableWidthGuide: UILayoutGuide } open class UIStackView { open var isLayoutMarginsRelativeArrangement: Bool } open class UITableView { @available(iOS 9.0, *) open var cellLayoutMarginsFollowReadableWidth: Bool }
• Use readableWidth • Use systemSpacing for spacing between views: !26 extension NSLayoutXAxisAnchor { open func constraint(equalToSystemSpacingAfter anchor: NSLayoutXAxisAnchor, multiplier: CGFloat) -> NSLayoutConstraint }