LoginSignup
0
1

More than 1 year has passed since last update.

【SwiftUI】ColorPickerを使ってみた

Last updated at Posted at 2023-04-25

はじめに

ColorPickerというUIコンポーネントの存在は知っていたのですが、
今まで使う機会がなかったので試しに使ってみます。

iOSのでの見た目

Simulator Screen Shot - iPhone 14 - 2023-04-25 at 17.34.28.png

macOSでの見た目

スクリーンショット 2023-04-25 17.35.27.png

基本的な使い方

import SwiftUI

struct ContentView: View {
    @State var color: Color = .red
    var body: some View {
        ColorPicker(selection: $color) {
            Text("ColorPicker")
        }
    }
}

カスタマイズ

ラベルを消す

import SwiftUI

struct ContentView: View {
    @State var color: Color = .red
    var body: some View {
        ColorPicker(selection: $color) {
            Text("ColorPicker")
        }
+       .labelsHidden()
    }
}

透明度を指定できなくする

import SwiftUI

struct ContentView: View {
    @State var color: Color = .red
    var body: some View {
+       ColorPicker(selection: $color, supportsOpacity: false) {
            Text("ColorPicker")
        }
    }
}

おわり

信じられないほど簡単ですねー
ただカスタマイズ性は低そうですね

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1