gpt4 book ai didi

iOS CGColor 与 UIColor

转载 作者:技术小花猫 更新时间:2023-10-29 10:10:53 29 4
gpt4 key购买 nike

我使用相同颜色的两种变体(浅色和深色)来创建渐变。

代码:

CAGradientLayer *gradient = [CAGradientLayer layer];

UIColor *light = [baseColor lightVersion];

UIColor *dark = [baseColor darkVersion];

gradient.colors = [NSArray arrayWithObjects:(id)[light CGColor], (id)[dark CGColor], nil];

问题是,我注意到原始 UIColor 版本的 CGColor 版本不同。这是为什么? UIColorCGColor 有什么区别,为什么不同?

最佳答案

UIColor 继承自 NSObject 并与 UIKit Framework 关联,而 CGColorCoreGraphics 关联CGColor 派生自 CFType

因此,如果您正在使用 UIKit 元素,那么您可以使用 UIColor,但是如果您使用 Core Graphics 进行绘图或使用 CALayer,则必须使用 CGColor

根据 UIColor 的文档

Many methods in UIKit require you to specify color data using aUIColor object, and for general color needs it should be your main wayof specifying colors. The color spaces used by this object areoptimized for use on iOS-based devices and are therefore appropriatefor most drawing needs. If you prefer to use Core Graphics colors andcolor spaces instead, however, you may do so.

关于iOS CGColor 与 UIColor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20140576/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com