---
title: "setTitle(_:for:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uibutton/settitle(_:for:)"
---

# setTitle(_:for:)

Sets the title to use for the specified state.

## Declaration

```swift
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. doc://com.apple.uikit/documentation/UIKit/UIControl/State-swift.struct describes the possible values.

## Discussion

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 state. If you don’t specify a title for the other states, the button uses the title associated with the normal state. If you don’t set the value for normal, then the property defaults to a system value. important: When the user interface idiom is UIUserInterfaceIdiom.mac and behavioralStyle is UIBehavioralStyle.mac, your app throws an exception if you use this method to set the title for any state other than normal.

## See Also

### Managing the title

- [titleLabel](uikit/uibutton/titlelabel.md)
- [title(for:)](uikit/uibutton/title(for:).md)
- [attributedTitle(for:)](uikit/uibutton/attributedtitle(for:).md)
- [setAttributedTitle(_:for:)](uikit/uibutton/setattributedtitle(_:for:).md)
- [titleColor(for:)](uikit/uibutton/titlecolor(for:).md)
- [setTitleColor(_:for:)](uikit/uibutton/settitlecolor(_:for:).md)
- [titleShadowColor(for:)](uikit/uibutton/titleshadowcolor(for:).md)
- [setTitleShadowColor(_:for:)](uikit/uibutton/settitleshadowcolor(_:for:).md)
