1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Xcode 12でUIDatePickerの背景色が変わらなくなってしまった

Posted at

問題のコード

datePicker.backgroundColor = .orange
if #available(iOS 13.4, *) {
    datePicker.preferredDatePickerStyle = .wheels
}

Xcode 12対応をしていてこんなコードを書いたら背景色が変わらなくなってしまったときの調査メモ。

調査メモ

let datePicker = UIDatePicker()

datePicker.backgroundColor = .orange           //=> UIExtendedSRGBColorSpace 1 0.5 0 1
datePicker.preferredDatePickerStyle = .wheels  //=> UIExtendedGrayColorSpace 0 0

datePicker.backgroundColor = .orange           //=> UIExtendedSRGBColorSpace 1 0.5 0 1
datePicker.preferredDatePickerStyle = .inline  //=> (nil)

datePicker.backgroundColor = .orange           //=> UIExtendedSRGBColorSpace 1 0.5 0 1 
datePicker.preferredDatePickerStyle = .compact //=> (nil)

スタイルを設定すると背景色が初期化されちゃいますよっと。

修正後のコード

if #available(iOS 13.4, *) {
    datePicker.preferredDatePickerStyle = .wheels
}
datePicker.backgroundColor = .orange
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?