Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
..
Failed to load latest commit information.
Images
Resources/Images.xcassets/LaunchImage.launchimage
50_icon.png
AppDelegate.cs
Buttons.csproj
Buttons.sln
ButtonsScreen_iPhone.xib
ButtonsScreen_iPhone.xib.cs
ButtonsScreen_iPhone.xib.designer.cs
ButtonsViewController.cs
Info.plist
Main.cs
README.md

README.md

id title brief article sdk
A9935042-877B-4CD1-8193-7D075439B7A7
Create Different Types of Buttons
This recipe shows you how to create the six different types of UIButton.

Recipe

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

System

DetailDisclosure

InfoDark

InfoLight

ContactAdd

Custom

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.