---
title: "Setting UIImage on a UIButton"  
description: "Previously, we learn how to set events on the UIButtonHandling Button Clicks Events Now, we will see how to set an image on UIButton. UIButtons have a"  
author: "Tarun Kumar"  
published: 2015-11-30  
updated: 2018-03-13  
canonical: https://www.mindstick.com/blog/10992/setting-uiimage-on-a-uibutton  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 2 minutes  

---

# Setting UIImage on a UIButton

Previously, we learn how to set events on the UIButton : [Handling Button Clicks Events](https://www.mindstick.com/Articles/11928/handling-button-clicks-events)

Now, we will see how to set an image on UIButton. UIButtons have a number of different [states](https://yourviews.mindstick.com/story/1549/top-indian-states-with-muslim-population). We can set only once the button image for all states but we can assign different values for all the states.

Ok, now we will see how to set images on different states and types:

For setting the ‘[default](https://www.mindstick.com/interview/12771/what-is-the-importance-of-default-resources)’ image on a button, we can call SetImage method

for UIControlState.Normal and the image you currently set will be used for all states.

##### Here is the example:

```
buttonObj = UIButton.FromType (UIButtonType.RoundedRect);

buttonObj.SetImage(UIImage.FromFile ("image.jpg"), UIControlState.Normal);
```

and also we can make each state different. \

On RoundedRect type of button only two states need to be set (when we set the image, we see the blue highlighted color on the button which is generated automatically that is the [transparent](https://www.mindstick.com/forum/1784/wpf-webbrowser-on-transparent-window) parts of the image).

For example:

```
buttonObj= UIButton.FromType(UIButtonType.RoundedRect);

buttonObj.SetImage(UIImage.FromFile ("imageName.jpg"), UIControlState.Normal);

buttonObj.SetImage(UIImage.FromFile ("imageName.jpg"), UIControlState.Disabled);
```

We can set the separate image for the [custom](https://www.mindstick.com/blog/12298/use-custom-writing-services-to-get-through-the-finals) button on the highlighted state, and also if we want to change the look or different image whenever the user will click on the button we can do it by [coding](https://www.mindstick.com/articles/12290/teaching-coding-from-the-metal-up-or-from-the-glass-back) like this:

```
buttonObj = UIButton.FromType(UIButtonType.Custom);

buttonObj.SetImage(UIImage.FromFile ("imageName.jpg"),UIControlState.Normal);

buttonObj.SetImage(UIImage.FromFile ("imageName.jpg "),UIControlState.Highlighted);

buttonObj.SetImage(UIImage.FromFile ("imageName.jpg "),UIControlState.Disabled);
```

(We can also set the different UIButton states by selecting one by one from the drop-down-list in the [Attribute](https://www.mindstick.com/blog/221/attributes-reflection) [Inspector](https://answers.mindstick.com/qa/39308/who-has-taken-charge-as-the-new-inspector-general-of-police-igp-kashmir-range) of the “[Interface](https://www.mindstick.com/articles/12101/interfaces-in-java-extending-interfaces) [Builder](https://www.mindstick.com/articles/12472/mgs-front-end-builder-for-magento-2-best-selling-product-on-magento-marketplace)” on Xcode.)

---

Original Source: https://www.mindstick.com/blog/10992/setting-uiimage-on-a-uibutton

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
