UIView

extension UIView
  • A simplified, @autoclosure-powered version of UIView.animate(withDuration:animations:).

    • You don’t need to use a closure—just write the code you want to animate as the first argument of the function.
    • Usage example: UIView.animate(myView.alpha = 0.5).

    Declaration

    Swift

    public static func animate(
        _ animation: @escaping @autoclosure () -> Void,
        withDuration duration: TimeInterval = 1.0
    )

    Parameters

    animation

    Required. The autoclosure to animate.

    duration

    Optional. The time interval; default is 1.0.

Auto Layout

  • Returns an array of constraints which, once activated, pin the view to its superview’s sides with optional insets.

    Note

    Note that this method does not set translatesAutoresizingMaskIntoConstraints on the view to false; you have to do it manually.

    Declaration

    Swift

    @available(iOS 9, *)
    public func constraintsToSuperview(
        with edgeInsets: UIEdgeInsets = .zero
    ) throws -> [NSLayoutConstraint]

    Parameters

    edgeInsets

    Optional. The insets to add between the view and its superview. Default is .zero.

  • Pins the view to its superview’s sides with optional insets.

    Declaration

    Swift

    @available(iOS 9, *)
    public func constrainToSuperview(with edgeInsets: UIEdgeInsets = .zero) throws

    Parameters

    edgeInsets

    Optional. The insets to add between the view and its superview. Default is .zero.