どうも、ちょげ(@chogetarou)です。
DatePickerのデフォルトの背景色を透明にする方法を紹介します。
方法
DatePickerのデフォルトの背景色を透明にするには、UIDatePickerを使います。
具体的には。initメソッドやonAppear修飾子などで、「UIDatePicker.appearance().backgroundColor」に「.clear」を代入します。
//initメソッドやonAppear修飾子で
UIDatePicker.appearance().backgroundColor = .clear
UIDatePicker.appearance().backgroundColorに「.clear」を代入することで、DatePickerのデフォルトの背景色を透明にすることができます。
使用例
以下は、使用例です。
struct ContentView: View {
@State var date = Date()
init () {
UIDatePicker.appearance().backgroundColor = .clear
}
var body: some View {
VStack{
DatePicker("Select Date", selection: $date)
.datePickerStyle(GraphicalDatePickerStyle())
.padding()
}
}
}
コメント