[Swift] I tried using ColorPicker (the one that can easily select colors) added in iOS14 [Swift UI]

Color Picker introduced from iOS 14 Until now, we have implemented PickerView and Slider by ourselves to provide color selection functions, etc. It may have been implemented, but it has become very easy to do.

environment

Implementation example

The selected color is used as the background color.

struct ContentView: View {
    @State private var color = Color.white
    var body: some View {
        ZStack{
            color
                .edgesIgnoringSafeArea(.all)
            ColorPicker(selection: $color, label: {
                Text("SelectColor")
            })
            .padding()
            .onChange(of: color, perform: { value in
                print(color)
            })
        }
    }
}

Now you can add ColorPicker. Changes during color selection can be handled with onChange. Is this area the same as a normal Picker?

motion

colorpicker480.gif

Remarks

The app has been released! Please install it if you like. Toranpo

I started Twitter! Please follow me if you like. @yajima_tohshu

Recommended Posts

[Swift] I tried using ColorPicker (the one that can easily select colors) added in iOS14 [Swift UI]
I tried using Realm with Swift UI
List of devices that can be previewed in Swift UI
I tried to summarize the words that I often see in docker-compose.yml
I tried using JWT in Java
[Ruby] I tried to summarize the methods that frequently appear in paiza
[Swift] I investigated the variable expansion "\ ()" that realizes the mysterious function of Swift UI.
[Ruby] I tried to summarize the methods that frequently appear in paiza ②
I tried using Elasticsearch API in Java
I tried using UICollectionViewListCell added from Xcode12.
I tried the new era in Java
I tried the AutoValue library in Intellij
I tried to easily put CentOS-7 in a PC that I no longer need
In Swift UI of iOS14, scrolling process of list can be controlled by code