I have 4 button with tag number: 0, 1, 2, 3. I want to change its color when clicking on it. So here is what I am doing:
switch ([sender tag]) {
case 0:
[myButton0 setBackgroundColor:[UIColor redColor]];
break;
case 1:
[myButton1 setBackgroundColor:[UIColor redColor]];
break;
case 2:
[myButton2 setBackgroundColor:[UIColor redColor]];
break;
case 3:
[myButton3 setBackgroundColor:[UIColor redColor]];
break;
}
my question is that if there is any way to shorten the code, like we set background color by it tag number?
Thank you
This is what i am doing. I have created a category on UIColor for colorWithHexValue. You can use your code.
Please use
};