<!--
{
  "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/UIButton/setTitle(_:for:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UIButton(im)setTitle:forState:"
  },
  "title" : "setTitle(_:for:)"
}
-->

# setTitle(_:for:)

Sets the title to use for the specified state.

```
func setTitle(_ title: String?, for state: UIControl.State)
```

## Parameters

`title`

The title to use for the specified state.

`state`

The state that uses the specified title. [`UIControl.State`](/documentation/UIKit/UIControl/State-swift.struct) describes the possible values.

## Discussion

Use this method to set the title for the button. The title you specify derives its formatting from the button’s associated label object. If you set both a title and an attributed title for the button, the button prefers the use of the attributed title over this one.

At a minimum, set the value for the [`normal`](/documentation/UIKit/UIControl/State-swift.struct/normal) state. If you don’t specify a title for the other states, the button uses the title associated with the [`normal`](/documentation/UIKit/UIControl/State-swift.struct/normal) state. If you don’t set the value for [`normal`](/documentation/UIKit/UIControl/State-swift.struct/normal), then the property defaults to a system value.

> Important:
> When the user interface idiom is ``doc://com.apple.uikit/documentation/UIKit/UIUserInterfaceIdiom/mac`` and ``doc://com.apple.uikit/documentation/UIKit/UIButton/behavioralStyle`` is ``doc://com.apple.uikit/documentation/UIKit/UIBehavioralStyle/mac``, your app throws an exception if you use this method to set the title for any state other than ``doc://com.apple.uikit/documentation/UIKit/UIControl/State-swift.struct/normal``.

---

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)