Convert SwiftUI Color to UIColor
Basically, Apple doesn't intend for you to do this conversion. SwiftUI's Color
is a View
, and the design of the framework is that data flows to a View
, which is then displayed. You are never supposed to extract data back from a View
.
If you find yourself needing to use the components of a color, you should work with UIColor
, and then convert to Color
at the time you are ready to display it.
If you are trying to get the components of system colors like Color.red
, I believe they are the same as the adaptive UIColor.systemRed
, which does have accessible components.
Standard Colors documentation
How to convert UIColor to SwiftUI‘s Color
Starting with beta 5, you can create a Color from a UIColor:
Color(UIColor.systemBlue)
how to change ui color to color set
UITableView.appearance().backgroundColor = UIColor(named: "your set here")
How to get a color opposite to primary color?
you can use the colors "label" and "systembackground", they are usually opposite.
So use UIColor.systemBackground and UIColor.systemLabel for the opposite
or UIColor.secondarySystemBackground and UIColor.secondarySystemLabel etc...
Related Topics
How to Display Uiview Over Keyboard in iOS
Using Sysctlbyname() from Swift
Swiftui How to Align a View That's Larger Than Screen Width
How to Get the iPhone Type from Simulator (Ios)
Calling a Method at Specific Time Every Day
Avaudiosession .Defaulttospeaker Changes Mic Input
Application Is "Ready to Sale" But Not Reflected on Itunes Store
How to Convert Video (In Gallery) to Nsdata? in Swift
Setting Up a Plist to Store Application Data (Not Settings) for an iPhone Game
Document Directory Path Change When Rebuild Application
Xcode Duplicate Symbols for Architecture Error After Updating Cocoa Pods
Remove Next/Previous Buttons (Inputaccessoryview) for Custom Keyboard in iOS8 Webview