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.
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...
iPhone SDK App - Change UIButton Text on Different States
For Normal State
[button setTitle:@"Normal" forState:UIControlStateNormal];
[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];
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.