Share on Google+Share on Google+

iPhone Change Button Text

Ads
The example illustrate how to change the text of UIButton on click. Basically UIButton is a object that is handled by UIControl class, which defines the behavior of all the objects such as UIButton, UILabel, sliders etc..

iPhone Change Button Text

The example illustrate how to change the text of UIButton on click. Basically UIButton is a object that is handled by UIControl class, which defines the behavior of all the objects such as UIButton, UILabel, sliders etc..

UIControl has number of states ...that can be recognized depending on the control.

enum {
UIControlStateNormal = 0,
UIControlStateHighlighted = 1 << 0,
UIControlStateDisabled = 1 << 1,
UIControlStateSelected = 1 << 2,
UIControlStateApplication = 0x00FF0000,
UIControlStateReserved = 0xFF000000
};

In our example we are going to change the text on UIButton on click and selection. To get the desired output we are using two different states of UIControl class...
1. UIControlStateNormal
2. UIControlStateHighlighted

iPhone SDK App - Change UIButton Text on Different States

For Normal State

[button setTitle:@"Normal" forState:UIControlStateNormal];

On selection

[button setTitle:@"Selected" forState:UIControlStateHighlighted];

In the above line of code "setTitle" is setting the title for button in different states... and "forState" will set the desired state.

Change UIButton Text Color: a developer can also change the text color on different states with the help of given code...

[changeText setTitleColor:[UIColor purpleColor] forState:UIControlStateNormal];

Download Code

Advertisements

Ads

Posted on: August 9, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Ads

Advertisement