Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIButton setTitleColor with RGB values not working

Tags:

iphone

I Have to set Title color for ffe1b1 to a UIButton.RGB value of ffe1b1 is 255,225,177. I am trying this code, but its not properly reflect. I search on net Color components are floats between 0.0 and 1.0 ! So what is proper way for giving That RGB Values.Thanks

   UIButton *btn   = [UIButton buttonWithType:UIButtonTypeCustom] ; 
btn.frame = CGRectMake(134.0, 193.0, 80.0, 30.0);


[btn setBackgroundImage:img forState:UIControlStateNormal];
[btn setTitle:@"Contact" forState:UIControlStateNormal];

[btn setTitleColor:[UIColor colorWithRed:255.0 green:225.0 blue:177.0 alpha:0.6 ]forState: UIControlStateNormal];
like image 511
triveni Avatar asked Dec 16 '22 07:12

triveni


2 Answers

Change the line like this

[btn setTitleColor:[UIColor colorWithRed:255.0 green:225.0 blue:177.0 alpha:0.6 ]forState: UIControlStateNormal];

to

[btn setTitleColor:[UIColor colorWithRed:(255.0/255) green:(225.0/255) blue:(177.0/255) alpha:0.6 ]forState: UIControlStateNormal];
like image 58
Ilanchezhian Avatar answered Jan 02 '23 08:01

Ilanchezhian


in objective c you cannot directly use RGB values. follow this link: http://www.touch-code-magazine.com/web-color-to-uicolor-convertor/

like image 20
gunas Avatar answered Jan 02 '23 10:01

gunas