---
title: "Buttons in iOS"  
description: "In iOS application development one element is very common that is Button, which is used for generating actions or taking some actions. In iOS for crea"  
author: "Tarun Kumar"  
published: 2015-11-29  
updated: 2019-03-31  
canonical: https://www.mindstick.com/articles/11927/buttons-in-ios  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 2 minutes  

---

# Buttons in iOS

In iOS [application development](https://www.mindstick.com/articles/65303/8-benefits-of-android-application-development-for-online-business) one element is very common that is Button, which is used for generating actions or taking some actions. In iOS for creating buttons provides UIButton class.\

##### There are a number of different built-in button types available, like:

##### - Add Contact

##### - Detail Disclosure

##### - Info Dark

##### - Info Light

##### - System (with custom font size, color and shadow)

##### - Custom (with image)

##### Setting Button Text

Now, we will see how to set the text on a UIButton. UIButton’s have a number of different states and we can set the [button text](https://www.mindstick.com/forum/23365/ios-how-to-get-button-text-from-tableview-cell) once for all states and also we can assign different values for each state.

For setting the ‘Click on Button’ text on a button, call SetTitle method for UIControlState.Normal and that text will be used for all states:

```
buttonObj = UIButton.FromType(UIButtonType.RoundedRect);buttonObj.SetTitle ("Click on Button", UIControlState.Normal);
```

We can also make each state different like these three states:

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

This is the normal button that we use mostly:

```
buttonObj.SetTitle("Normal Button", UIControlState.Normal);
```

To set [button as](https://answers.mindstick.com/qa/32548/do-you-ever-use-the-favorite-button-as-a-bookmark-on-twitter) highlighted use this code:

```
buttonObj.SetTitle("Highlighted Button", UIControlState.Highlighted);
```

To disable the button use this code:

```
buttonObj.SetTitle("Disabled Button", UIControlState.Disabled);
```

To set the Title button [text color](https://www.mindstick.com/forum/158651/what-is-the-css-property-used-to-change-the-text-color-of-an-element) light gray:

```
buttonObj.SetTitleColor(UIColor.LightGray, UIControlState.Disabled);
```

We can also set these different states using ‘Type’ in ‘[Attribute](https://www.mindstick.com/blog/61/ado-dot-net-object-model-and-attributes) [Inspector](https://answers.mindstick.com/qa/42036/which-man-did-general-washington-make-the-chief-inspector-of-the-colonial-troops)’ in Xcode by choosing each one from the drop-down-list of the [properties](https://yourviews.mindstick.com/view/81845/now-it-s-possible-to-predict-properties-of-any-molecule) panel.

***Next, we will learn how to handle [button clicks](https://www.mindstick.com/forum/158690/how-can-you-handle-user-interactions-such-as-button-clicks-using-jquery)*** : *Handling Button Clicks Events*

---

Original Source: https://www.mindstick.com/articles/11927/buttons-in-ios

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
