1

iOS アプリで色選択を実装するのを手伝ってくれる人がいるかどうか疑問に思っていました。今のところ塗装ラインは黒のみですが、ユーザーが色を変えられるようにしてほしいです。現在、5 つの異なる色オプション用の 5 つのボタンがあります。次に、各ボタン 1 ~ 5 にタグを付け、それらすべてを 1 つの に接続しましたIBAction。ボタンに 1 のタグが付けられているかどうかを示す if ステートメントを作成し、各色の色を 1.0、0.0、0.0、1.0 (赤) などに設定できると考えていました。だから、ここに私が持っているif文があります:

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";
    }
}

それで、変数の色を入れたので

CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), color );

しかし、「関数呼び出しの引数が少なすぎます。5 が必要ですが、2 があります」というエラーが表示されます。

ご協力いただきありがとうございます!

-カール

4

2 に答える 2

1

ご協力ありがとうございますが、最後の部分は自分で考え出しました。誰かが興味を持っているなら、これは私が思いついたコードです:

double C1 = 1.15;
double C2 = 0.15;
double C3 = 0.15;
double C4 = .8;

'NSString *color = @"0.15, 1.15, 0.15, .8";

-(IBAction)colors:(id)sender{

if (([sender tag] ==1)) {
    C1=  0.15;
    C2 = 0.15;
    C3 = 0.15;
    C4 = .8;
}

else if (([sender tag] ==2)) {

    C1 = 0.15;
    C2 = 1.15;
    C3 = 0.15;
    C4 = .8;
}

else if (([sender tag] ==3)) {
    color = @"1.15, 0.15, 0.15, .8";
    C1 = 1.15;
    C2 = 0.15;
    C3 = 0.15;
    C4 = .8;
}

else if (([sender tag] ==4)) {
    C1 = 0.15;
    C2 = 0.15;
    C3 = 1.15;
    C4 = .8;
}
else if (([sender tag] ==5)) {
    C1 = 1.15;
    C2 = 1.15;
    C3 = 0.15;
    C4 = .8;
}

}

CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), C1, C2, C3, C4 );
于 2012-06-21T16:58:07.397 に答える
0
/*
[colorArray addObject:@"0.0,0.0,0.0"];      
[colorArray addObject:@"148.0,0.0,211.0"];  
[colorArray addObject:@"0.0,191.0,255.0"];  
...
*/

-(IBAction)actionColorButton:(id)sender
{
[self setPenColor:[colorArray objectAtIndex:[sender tag] - 1]];
}

-(void)setPenColor:(NSString*)color
{
NSArray *arr = [color componentsSeparatedByString:@","];

colorRed = [[arr objectAtIndex:0] floatValue] / 255.0;
colorGreen = [[arr objectAtIndex:1] floatValue] / 255.0;
colorBlue = [[arr objectAtIndex:2] floatValue] / 255.0;
...
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 
                           colorRed,
                           colorGreen,
                           colorBlue,
                           1.0);
...
}
于 2012-06-19T18:59:07.430 に答える