iOS:UIColor不尊重红色,绿色,alpha,蓝色。显示其他颜色?

时间:2014-09-04 22:39:03

标签: ios objective-c uicolor

我是iOS编程的新手。我使用sketch

设计了iOS个应用屏幕

我在Sketch中使用调色板设计的标签看起来像是 enter image description here enter image description here

但是,当我在我的代码中执行此操作时,我会

    self.yearHeaderLabel.font = [UIFont fontWithName:@"HelveticaNeue-Thin" size:30];
    self.yearHeaderLabel.textColor = [UIColor colorWithRed:51 green:51 blue:51 alpha:100];

但是当我运行我的应用程序时,我看到了 enter image description here

有什么问题
self.yearHeaderLabel.textColor = [UIColor colorWithRed:51 green:51 blue:51 alpha:100];  

为什么不尊重颜色?

3 个答案:

答案 0 :(得分:2)

小修正:

self.yearHeaderLabel.textColor = [UIColor colorWithRed:51.0/255.0 green:51.0/255.0 blue:51.0/255.0 alpha:1];

答案 1 :(得分:1)

你只需做一个小改动。 [UIColor:colorWithRed:green:blue:alpha]浮点数,而不是 ints 作为参数。请尝试以下方法:

self.yearHeaderLabel.textColor = [UIColor colorWithRed:51/255. green:51/255. blue:51/255. alpha:1]; 

答案 2 :(得分:1)

你应该放置我在下面提到的值,否则它将无法正常工作

[UIColor colorWithRed:51.0/255.0 green:51.0/255.0 blue:51.0/255.0 alpha:1.0]; 

这意味着您需要将值标准化,以使值在范围<0,1&gt;

编辑(根据对该答案的一些评论):

AppCode对这种版本感到满意的那种传递值抱怨:

UIColor colorWithRed:(CGFloat)(51.0/255.0) green:(CGFloat)(51.0/255.0) blue:(CGFloat)(51.0/255.0) alpha:1.0];