I was wondering if anyone could help me implement color selection in my iOS app. Right now, the painting line is only black, but I’d like the user to be able to change the color. Right now I have 5 buttons for 5 different color options. I then tagged each button 1-5, and connected them all to a single IBAction. I was thinking I could have an if statement to say if the button is tagged 1, then set color to 1.0, 0.0, 0.0, 1.0 (red) and so on for each color.
So, here are the if statements I have:
NSString *color = @"0.15, 1.15, 0.15, .8";
-(IBAction)color:(id)sender{
if ([sender tag] ==1) {
color = @"0.15, 1.15, 0.15, .8";
}
if ([sender tag] ==2) {
color = @"0.15, 1.15, 0.15, .8";
}
if ([sender tag] ==3) {
color = @"0.15, 1.15, 0.15, .8);";
}
if ([sender tag] ==4) {
color = @"(0.15, 1.15, 0.15, .8";
}
if ([sender tag] ==5) {
color = @"0.15, 1.15, 0.15, .8";
}
}
So, now that I put the variable color in
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), color );
But, I’m getting the error “Too few arguments to function call, expected 5, have 2”
Thanks for your help!
-Karl
Thanks for all your help, but I figured out the last part on my own.
If anyone’s interested, this is the code I came up with: