SwiftUI_visionOS_Note

ColorPicker()

Jan 18, 2024
1 min read|
  • colorPicker() introduces color customization options for users.
  • It simplifies incorporation of color selection in the app.
  • Eliminates the need for complex custom color solutions.

1. Write the base code

  • Ztack, clear background, ignore safe area, and title
ZStack{
            Color.clear
                .ignoresSafeArea(.all)
            
                .navigationTitle("Title")
        }
swift

2. Add ColorPicker

  • Select the one with titleKey, selection & supportsOpacity.
  • Create color variable and bind it to ZStack
@State var backgroundColor: Color = .clear
swift
ZStack{
            backgroundColor
                .ignoresSafeArea(.all)
            
            ColorPicker("Select a color", selection: $backgroundColor, supportsOpacity: true)
            
            
            
                .navigationTitle("Title")
        }
swift

3. Stylize colorPicker()

ColorPicker("Select a color", 
                        selection: $backgroundColor,
                        supportsOpacity: true)
            .padding()
            .glassBackgroundEffect(displayMode: .always)
            .foregroundStyle(.green)
            .font(.title)
            .frame(depth: 30)
						.padding(50)
swift

Subscribe to our newsletter

Get the latest news and updates from our team