Contents

addSubview(_:positioned:relativeTo:)

Inserts a view among the view’s subviews so it’s displayed immediately above or below another view.

Declaration

func addSubview(_ view: NSView, positioned place: NSWindow.OrderingMode, relativeTo otherView: NSView?)

Parameters

  • view:

    The view object to add to the view as a subview.

  • place:

    An enum constant specifying the position of the aView relative to otherView. Valid values are NSWindowAbove or NSWindowBelow.

  • otherView:

    The other view aView is to be positioned relative to. If otherView is nil (or isn’t a subview of the view), aView is added above or below all of its new siblings.

Discussion

This method also sets the view as the next responder of aView.

The view retains aView. If you use removeFromSuperview() to remove aView from the view hierarchy, aView is released. If you want to keep using aView after removing it from the view hierarchy (if, for example, you are swapping through a number of views), you must retain it before invoking removeFromSuperview().

See Also

Related Documentation

Adding and Removing Subviews