0

何らかの理由でステッパーから取得した RGB 値を使用してビューの背景を変更したいのですが、うまくいきません。助けてください!

int red1,green1,blue1;

 -(BOOL)textFieldShouldReturn:(UITextField *)textField
    {
        [textField resignFirstResponder];
        return NO;
    }
    -(IBAction)stepper:(UIStepper *)mystep
    {
        if(mystep.tag==1)
        {
            red1=(int)mystep.value;
            txt1.text=[NSString stringWithFormat:@"%d",red1];
        }
        if(mystep.tag==2)
        {
            green1=(int)mystep.value;
            txt2.text=[NSString stringWithFormat:@"%d",green1];
        }
        if(mystep.tag==3)
        {
            blue1=(int)mystep.value;
            txt3.text=[NSString stringWithFormat:@"%d",blue1];
        }
    }
    -(IBAction)btnPressed
    {
        view1.backgroundColor=[UIColor colorWithRed:red1 green:green1 blue:blue1 alpha:1.0];
    }
4

1 に答える 1

0

colorWithRed:green:blue:alpha:メソッドのパラメーターは0.0~ (CGFloat) の範囲内にある必要があります。したがって、 ~1.0の範囲の値を取得している場合は、コードを次のように変更します。0255

view1.backgroundColor=[UIColor colorWithRed:red1/255.0 green:green1/255.0 blue:blue1/255.0 alpha:1.0];
于 2015-06-15T12:15:08.177 に答える