xcode - iOS , Changing view background colour using stepper -
i want change background of view using rgb values obtained stepper reason 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 colorwithred:green:blue:alpha: method should in range of 0.0 1.0 (cgfloat) in case taking values in range of 0 255, change code to:
view1.backgroundcolor=[uicolor colorwithred:red1/255.0 green:green1/255.0 blue:blue1/255.0 alpha:1.0];
Comments
Post a Comment