I want to change the background of view using rgb values obtained from stepper for some reason it isn.t working,please help!
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];
}
The parameters in the
colorWithRed:green:blue:alpha:
method should be in the range of0.0
to1.0
(CGFloat) So in case you are taking values in the range of0
to255
, then change the code to: