Carl Spackler
Carl Spackler

Reputation: 263

Changing a button's font color when touched in iOS

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

Answers (2)

Sabby
Sabby

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

Aitul
Aitul

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

Related Questions