0

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?

rmaddy
  • 314,917
  • 42
  • 532
  • 579

1 Answers1

6

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.

clemens
  • 16,716
  • 11
  • 50
  • 65