Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.

id title brief article sdk
Create Different Types of Buttons
This recipe shows you how to create the six different types of UIButton.


There are six different types of UIButton, enumerated in UIButtonType:







This screenshot shows the different types, along with two different custom buttons: one with an image and one with formatted text. There is no real visual difference between some of these button types in iOS 7 and later.

The sample code includes two different ViewControllers: one using an XIB file and the other creating all the controls in C# code.

  • To create a button in code, use the UIButton.FromType static method like this:
var buttonRect = UIButton.FromType(UIButtonType.System);
  • If a text label is required, it is set using the SetTitle method:
buttonRect.SetTitle ("Button!", UIControlState.Normal);

If you use Interface Builder to create your user interface then you can choose the button Type in the Attributes Inspector and set the other properties appropriately.

Additional Information

Buttons have multiple states (including Disabled, Selected and Highlighted). In the example above the properties are only set for the Normal state, however properties such as Title and TitleColor can be set independently for each state. See the Set Button Text recipe for an example.