How to Change a Swiftui Color to Uicolor

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



Leave a reply



Submit