问题描述
我使用相同颜色的两种变体,浅色和深色版本来创建渐变。
I am using 2 variations of the same color, a light and dark version, to create a gradient.
代码:
CAGradientLayer *gradient = [CAGradientLayer layer];
UIColor *light = [baseColor lightVersion];
UIColor *dark = [baseColor darkVersion];
gradient.colors = [NSArray arrayWithObjects:(id)[light CGColor], (id)[dark CGColor], nil];
问题是,我注意到 CGColor
原始 UIColor
版本的版本不同。这是为什么? UIColor
和 CGColor
有什么区别?为什么它们不同?
The problem is, I noticed that the CGColor
version of the original UIColor
version is different. Why is that? What is the difference between the UIColor
and CGColor
and why are they different?
推荐答案
UIColor
是继承自 NSObject
并与之关联 UIKit Framework
,而 CGColor
与 CoreGraphics
和<$相关联c $ c> CGColor 派生自 CFType
。
UIColor
is Inherits from NSObject
and associated with UIKit Framework
while CGColor
is associated with CoreGraphics
and CGColor
is derived from CFType
.
所以如果你正在使用UIKit元素然后你可以使用 UIColor
,但是如果你使用Core Graphics使用绘图或使用 CALayer
你必须使用 CGColor
。
So if you are using UIKit elements then you can use UIColor
, But if you are using drawing using Core Graphics or working with CALayer
you must use CGColor
.
根据
这篇关于iOS CGColor与UIColor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!