UIColor colorWithRed:green:blue:总是产生黑色 [英] UIColor colorWithRed:green:blue: always produces black
本文介绍了UIColor colorWithRed:green:blue:总是产生黑色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到过很多情况下,当我试图通过代码自定义颜色,结果是非常不同的Photoshop,例如
I have come across many instances when I try to make custom color through code and the result is quite different from Photoshop, e.g
[UIColor colorWithRed:(160/255) green:(97/255) blue:(5/255) alpha:1];
所得的颜色是黑色的,而我应该是黄色的。
the resultant color is blackish, whereas it should me something like yellow. When working using sliders, the result is as expected.
我的Xcode有问题,还是一个常见问题?
Is there a problem with my Xcode or it is a general issue?
推荐答案
除法整数导致整数除法,实质上意味着截断结果的小数部分。使用
Dividing integers results in integer division that essentially means truncating the fractional part of the result. Use
[UIColor colorWithRed:(160/255.0) green:(97/255.0) blue:(5/255.0) alpha:1.0]
。
这篇关于UIColor colorWithRed:green:blue:总是产生黑色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文