Reputation: 263
I'm brand new to iOS with only Action Script 3.0 as a programming background. Objective C is looking unbelievably foreign to me thus far. I'm working with the latest version of Xcode and am trying to learn by taking baby steps, and too many tutorials start at far too high a level for a new guy like me.
I'm trying to have a label or button change font color when it is touched, and return to its original color when it is touched again. I know it's probably stupidly simple, but I need to start somewhere. Thanks much.
Upvotes: 2
Views: 1005
Reputation: 403
@interface ViewController ()
{
BOOL muteIsSelected;
}
@end
- (IBAction)yourButton:(id)sender {
if(muteIsSelected == false)
{
yourButton.backgroundColor = [UIColor redColor];
muteIsSelected = true;
}
else if (muteIsSelected == true)
{
yourButton.backgroundColor = [UIColor blackColor];
muteIsSelected = false;
}
}
Upvotes: 0
Reputation: 2992
It is very easy to change a UIButton
color property when it is touched.
-(IBAction)changeColor:(id)sender
{
UIButton *btn = (UIButton *)sender;
if(btn.enabled)
{
btn.enabled=NO;
btn.backgroundColor=[UIColor blueColor];
}
else
{
btn.enabled=YES;
btn.backgroundColor=[UIColor greenColor];
}
}
Upvotes: 2