[SwiftUI]DatePickerのラベルの色を変えるには?

SwiftUI

どうも、ちょげ(@chogetarou)です。

DatePickerのラベルの色を変える方法を紹介します。

スポンサーリンク

方法

インターフェース, インターネット, プログラム, ブラウザ, Www

DatePickerのラベルの色を変えるには、foregroundColor修飾子を使います。

まず、DatePickerにforegroundColor修飾子を付与します。

そして、foregrounColorの引数にラベルの色を指定します。

DatePicker("", selection: $date)
     .foregroundColor(labelColor)

foregroundColor修飾子を使うことで、DatePickerのラベルの色を設定することができます。

使用例

以下は、使用例です。

struct ContentView: View {
    @State var date = Date()
    
    var body: some View {
        VStack{
            DatePicker("Select Date", selection: $date)
                .foregroundColor(Color.red)
                .padding()
        }
    }
}

コメント

タイトルとURLをコピーしました