Reputation: 140
Im trying this, but when i press it it dont changes, it only displays text. Also tried if else functions, but with no results.
.h
IBOutlet UIButton *poga1;
@property (nonatomic, retain) UIButton *poga1;
.m
@synthesize poga1;
- (void)viewDidLoad
{
[super viewDidLoad];
[poga1 setTitle:@"My Title" forState:UIControlStateNormal];
[poga1 setTitle:@"My Selected Title" forState:UIControlStateSelected];
}
Upvotes: 1
Views: 2604
Reputation: 2017
Try this: If you added a title through the storyboard (the gui interface) then delete it.
.h //create an IBOutlet action. How? You right-click the button and drag it to the .h file. A pop up happens and you need to click the drop down and switch it to action //should be something like
- (IBAction)yourButton:(id)sender;
.m
//there will be a new function in your .m which is your button action function.
@synthesize poga1;
- (void)viewDidLoad
{
[super viewDidLoad];
[poga1 setTitle:@"My Title" forState:UIControlStateNormal];
[poga1 setTitle:@"My Selected Title" forState:UIControlStateSelected];
}
- (IBAction)Start:(id)sender
{
/* if you want this to change the text each time it's pressed then, you need a global counter that your increment each time the button is pressed. then you will have a if statement saying if the counter is equal to 1 (pressed once) then set title to hello, if the counter is equal to 7 (pressed 7 times) set title to goodbye. */
[sender setTitle:@"whatever" forState:UIControlStateNormal];
}
Upvotes: 1
Reputation: 20410
You need to capture the action of the button and change the title, cause UIButton doenst have a permanent state as selected, like a switch or a toggle.
If you want to change the title when the user press:
-(IBAction) onClick: (id) sender {
[(UIButton *) sender setHighlighted:YES];
}
Upvotes: 0