I have written this code to change colour of different labels through different buttons
I am new to app development, just got stuck up in pretty basics:
-(IBAction)ButtonPressed:(id)sender
{
UIButton *btn=sender;
if(btn.tag==1)
{
lbl1.text=@"";
lbl1.backgroundColor=[UIColor redColor];
}
if(btn.tag==2)
{
lbl2.text=@"";
lbl2.backgroundColor=[UIColor greenColor];
}
else if(btn.tag==3)
{
lbl3.text=@"";
lbl3.backgroundColor=[UIColor magentaColor];
}
else if(btn.tag==4)
{
lbl4.text=@"";
lbl4.backgroundColor=[UIColor blueColor];
}
else if(btn.tag==5)
{
lbl5.text=@"";
lbl5.backgroundColor=[UIColor brownColor];
}
}
After writing the code the colour of label one is only getting changed. I have connected all the elements through storyboard though
Try it like this
Or Simply
Also check the tags of the buttons.