Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
Images
Resources/Images.xcassets/LaunchImage.launchimage
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
D01169DB-BC0D-3DDA-1D37-D1873EA1688A
Set Button Text
This recipe shows you how to set the text on a UIButton.

Recipe

Buttons have a number of different states, and you can set the button text once for all states or assign different values for each state.

To set the ‘default’ text for a button, call SetTitle for UIControlState.Normal and that text will be used for all states:

buttonRect = UIButton.FromType(UIButtonType.RoundedRect);
buttonRect.SetTitle ("Click me", UIControlState.Normal);

Alternatively you can make each state different, as this image shows:

The code for these three states is:

buttonRect = UIButton.FromType(UIButtonType.RoundedRect);
buttonRect.SetTitle ("Click me", UIControlState.Normal);
buttonRect.SetTitle ("Clicking me", UIControlState.Highlighted);
buttonRect.SetTitle ("Disabled", UIControlState.Disabled);
buttonRect.SetTitleColor (UIColor.LightGray, UIControlState.Disabled);

You can also set the different states using the Xamarin Designer for iOS by choosing each one from the drop-down-list of the properties panel.

You can’t perform that action at this time.