UIButton setTitleColor with RGB values ​​not working

I need to set the header color for ffe1b1 to UIButton.RGB for ffe1b1 - 255,225,177. I am trying to use this code, but it is incorrectly reflected. I am searching on the net. Color components are floating values ​​from 0.0 to 1.0! So, what is the right way to provide 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]; 
+4
source share
2 answers

Change the line as follows

 [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]; 
+10
source

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

+2
source

Source: https://habr.com/ru/post/1381077/


All Articles