iOS CGColor versus UIColor

后端 未结 4 923
轻奢々
轻奢々 2020-12-05 15:41

I am using 2 variations of the same color, a light and dark version, to create a gradient.

Code:

CAGradientLayer *gradient = [CAGradientLayer layer];         


        
相关标签:
4条回答
  • 2020-12-05 15:58

    After reading your question, I tried a sample project in which I took a label with a background color having RGB values (100,100,100). And set its border color to same RGB values but it is CGColor but I found no difference in them. Refer attached image. Border width is 5 pixels.Label with same background color and border color

    0 讨论(0)
  • 2020-12-05 16:03

    There is no difference between UIColour and CGColour.

    0 讨论(0)
  • 2020-12-05 16:05

    UIColor is Inherits from NSObject and associated with UIKit Framework while CGColor is associated with CoreGraphics and CGColor is derived from CFType.

    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.

    As per Documentation of UIColor

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

    0 讨论(0)
  • 2020-12-05 16:10

    UIColor is just an Objective-C object wrapper of the C object CGColor. There should be no difference.

    0 讨论(0)
提交回复
热议问题