<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIStackView/insertArrangedSubview(_:at:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIStackView(im)insertArrangedSubview:atIndex:"
  },
  "title" : "insertArrangedSubview(_:at:)"
}
-->

# insertArrangedSubview(_:at:)

Adds the provided view to the array of arranged subviews at the specified index.

```
func insertArrangedSubview(_ view: UIView, at stackIndex: Int)
```

## Parameters

`view`

The view to add to the array of views arranged by the stack.

`stackIndex`

The index where the stack inserts the new view in its [`arrangedSubviews`](/documentation/UIKit/UIStackView/arrangedSubviews) array. This value must not be greater than the number of views currently in this array. If the index is out of bounds, this method throws an <doc://com.apple.documentation/documentation/Foundation/NSExceptionName/internalInconsistencyException> exception.

## Discussion

If index is already occupied, the stack view increases the size of the [`arrangedSubviews`](/documentation/UIKit/UIStackView/arrangedSubviews) array and shifts all of its contents at the index and above to the next higher space in the array. Then the stack view stores the provided view at the index.

The stack view also ensures that the [`arrangedSubviews`](/documentation/UIKit/UIStackView/arrangedSubviews) array is always a subset of its [`subviews`](/documentation/UIKit/UIView/subviews) array. This method automatically adds the provided view as a subview of the stack view, if it isn’t already. When adding subviews, the stack view appends the view to the end of its [`subviews`](/documentation/UIKit/UIView/subviews) array. The index only affects the order of views in the [`arrangedSubviews`](/documentation/UIKit/UIStackView/arrangedSubviews) array. It doesn’t affect the ordering of views in the [`subviews`](/documentation/UIKit/UIView/subviews) array.

## See Also

[`-  removeFromSuperview`](/documentation/UIKit/UIView/removeFromSuperview())

Unlinks the view from its superview and its window, and removes it from the responder chain.

[`-  initWithArrangedSubviews:`](/documentation/UIKit/UIStackView/init(arrangedSubviews:))

Returns a new stack view object that manages the provided views.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)