uibutton – 如何从RGB值正确初始化UIColor?

前端之家收集整理的这篇文章主要介绍了uibutton – 如何从RGB值正确初始化UIColor?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用各种颜色的iPhone应用程序。当用户选择特定颜色按钮时,我设置绘图颜色。我得到一些颜色,但在大多数情况下,我得到白色。

这里是我的代码

-(IBAction)colorSelected:(UIButton *)sender
{

switch (sender.tag) 
{
    case 1:
        self.drawcolor= [UIColor colorWithRed:200 green:191 blue:231 alpha:1];
        break;            
    case 2:
        self.drawcolor= [UIColor colorWithRed:163 green:73 blue:164 alpha:1];
        break;  
    case 3:
        self.drawcolor= [UIColor colorWithRed:112 green:146 blue:76 alpha:1];
        break;  
    case 4:
        self.drawcolor= [UIColor colorWithRed:63 green:72 blue:204 alpha:1];
        break;  
    case 5:
        self.drawcolor= [UIColor colorWithRed:153 green:217 blue:234 alpha:1];
        break;  
    case 6:
        self.drawcolor= [UIColor colorWithRed:0 green:162 blue:232 alpha:1];
        break;          
    case 7:
        self.drawcolor= [UIColor colorWithRed:181 green:230 blue:29 alpha:1];
        break;  
    case 8:
        self.drawcolor= [UIColor colorWithRed:34 green:177 blue:76 alpha:1];
        break;          
    case 9:
        self.drawcolor= [UIColor colorWithRed:239 green:228 blue:176 alpha:1];
        break;          
    case 10:
        self.drawcolor= [UIColor colorWithRed:255 green:201 blue:0 alpha:1];
        break;          
    case 11:
        self.drawcolor= [UIColor colorWithRed:255 green:201 blue:14 alpha:1];
        break;          
    case 12:
        self.drawcolor= [UIColor colorWithRed:237 green:28 blue:36 alpha:1];
        break;          
    case 13:
        self.drawcolor= [UIColor colorWithRed:255 green:127 blue:39 alpha:1];
        break;          
    case 14:
        self.drawcolor= [UIColor colorWithRed:255 green:174 blue:201 alpha:1];
        break;          
    case 15:
        self.drawcolor= [UIColor colorWithRed:185 green:122 blue:87 alpha:1];
        break;          
    case 16:
        self.drawcolor= [UIColor colorWithRed:136 green:0 blue:21 alpha:1];
        break;          
    case 17:
        self.drawcolor= [UIColor colorWithRed:195 green:195 blue:195 alpha:1];
        break;          
    case 18:
        self.drawcolor= [UIColor colorWithRed:127 green:127 blue:127 alpha:1];
        break;          
    case 19:
        self.drawcolor= [UIColor colorWithRed:255 green:255 blue:255 alpha:1];
        break;
    case 20:
        self.drawcolor= [UIColor colorWithRed:0 green:0 blue:0 alpha:1];
        break;  
    default:
        break;
}

self.preColor=self.drawcolor;
self.lineWidth=self.prelineWidth;
}

任何人都可以告诉我我做错了什么?
Sumit

解决方法

这些值在0.0到1.0的范围内。

例如。除以255,但记住小数点,所以你得到浮点除法而不是整数除法。

喜欢

selectedColor = [UIColor colorWithRed:14.0/255.0 green:114.0/255.0 blue:199.0/255.0 alpha:1];
原文链接:https://www.f2er.com/css/223194.html

猜你在找的CSS相关文章