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

# setRightBarButton(_:animated:)

Sets the custom bar button item, optionally animating the transition to the view.

```
func setRightBarButton(_ item: UIBarButtonItem?, animated: Bool)
```

## Parameters

`item`

A custom bar item to display on the right of the navigation bar.

`animated`

Specify <doc://com.apple.documentation/documentation/Swift/true> to animate the transition to the custom bar item when this item is the top item. Specify <doc://com.apple.documentation/documentation/Swift/false> to set the item immediately without animating the change.

## Discussion

If two navigation items have the same custom left or right bar button items, those bar button items remain stationary during the transition when the navigation item is pushed or popped.

---

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)