How can I change a SwiftUI Color to UIColor?

SwiftUI 2.0

There is a new initializer that takes a Color and returns a UIColor for iOS or NSColor for macOS now. So:

iOS

UIColor(Color.red)

macOS

NSColor(Color.red)

Core Graphics

UIColor(Color.red).cgColor /* For iOS */
NSColor(Color.red).cgColor /* For macOS */

If you are looking for color components, you can find a helpful extensions here in this answer

Also, check out How to convert UIColor to SwiftUI‘s Color

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)