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

# setImage(_:for:)

Sets the image to use for the specified state.

## Declaration

```swift
func setImage(_ image: UIImage?, for state: UIControl.State)
```

## Parameters

- `image`: The image to use for the specified state.
- `state`: The state that uses the specified image. The values are described in doc://com.apple.uikit/documentation/UIKit/UIControl/State-swift.struct.

## Discussion

Discussion At a minimum, always set an image for the normal state when associating images to a button. If you don’t specify an image for the other states, the button uses the image associated with normal. If you don’t specify an image for the normal state, the button uses 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 image for any state other than normal.

## See Also

### Managing images and tint color

- [backgroundImage(for:)](uikit/uibutton/backgroundimage(for:).md)
- [image(for:)](uikit/uibutton/image(for:).md)
- [setBackgroundImage(_:for:)](uikit/uibutton/setbackgroundimage(_:for:).md)
- [preferredSymbolConfigurationForImage(in:)](uikit/uibutton/preferredsymbolconfigurationforimage(in:).md)
- [setPreferredSymbolConfiguration(_:forImageIn:)](uikit/uibutton/setpreferredsymbolconfiguration(_:forimagein:).md)
- [tintColor](uikit/uibutton/tintcolor.md)
