Initializer

init(nsColor:)

Creates a color from an AppKit color.

Declaration 宣言

init(nsColor: NSColor)

Parameters パラメータ

color

An NSColor instance from which to create a color.

Discussion 議論

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 linkColor 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:

A side by side comparison of light and dark appearance screenshots of

See Also 参照

Creating a Color from Another Color