Why there is CGColor when we already have UIColor in IOS? If they are different then what is the difference between them?

748 Views Asked by At

I just wanted to know why there are two ways to obtain color in iOS. I am new to Swift and Objective C development, I just want to know how and why they are different?

1

There are 1 best solutions below

8
clemens On

CGColor comes from a lower level than UIColor. This difference is not so obvious in Swift anymore, but you may see this in Objective-C where UIColor is an Objective-C class with methods while CGColor is a C type and you access it with C functions.

UIColor is part of the UIKit which is based on Core Graphics, where CGColor belongs to. While UIKit is for iOS (and tvOS), Core Graphics is for macOS and iOS, and you may share code for Core Graphics between both.

Roughly speaking, Core Graphics is for drawing while UIKit and its macOS pendant AppKit are for GUI display.