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

# setAttributedTitle(_:for:)

Sets the styled title to use for the specified state.

```
func setAttributedTitle(_ title: NSAttributedString?, for state: UIControl.State)
```

## Parameters

`title`

The styled text string so use for the title.

`state`

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

## Discussion

Use this method to set the title of the button, including any relevant formatting information. If you set both a title and an attributed title for the button, the button prefers the use of the attributed title.

At a minimum, you should set the value for the normal state. If a title is not specified for a state, the default behavior is to use the title associated with the [`normal`](/documentation/UIKit/UIControl/State-swift.struct/normal) state. If the value for [`normal`](/documentation/UIKit/UIControl/State-swift.struct/normal) is not set, then the property defaults to a system value.

---

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)