UIButton setTitleColor与RGB值不工作



我必须将ffe1b1的标题颜色设置为UIButton。ffe1b1的RGB值为255,225,177。我正在尝试这个代码,但它没有正确反映。我在网上搜索颜色组件是浮动在0.0和1.0之间!所以什么是适当的方式给予RGB值。由于

   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];

像这样修改行

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

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

在objective c中你不能直接使用RGB值。点击此链接:http://www.touch-code-magazine.com/web-color-to-uicolor-convertor/

最新更新