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. |
|
|
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.