init(uiColor : UIColor)
Creates a color from a UIKit color.
init(cgColor : CGColor)
Creates a color from a Core Graphics color.
var cgColor : CGColor?
A Core Graphics representation of the color, if available.
Availability 有効性
Technology
init(nsColor: NSColor
)
color
An NSColor
instance from which to create a color.
Use this method to create a SwiftUI color from an NSColor
instance. The new color preserves the adaptability of the original. For example, you can create a rectangle using link
to see how the shade adjusts to match the user’s system settings:
struct Box: View {
var body: some View {
Color(nsColor: .linkColor)
.frame(width: 200, height: 100)
}
}
The Box
view defined above automatically changes its appearance when the user turns on Dark Mode. With the light and dark appearances placed side by side, you can see the subtle difference in shades:
Note 注意
Use this initializer only if you need to convert an existing NSColor
to a SwiftUI color. Otherwise, create a SwiftUI Color
using an initializer like init(_:
, or use a system color like blue
.
init(uiColor : UIColor)
init(cgColor : CGColor)
var cgColor : CGColor?