简体   繁体   中英

How to override iOS dark mode style for datepicker

在此处输入图片说明

Like you can see the selected value in date picker is white. If I change the date, it won't become visible. This a screenshot of iOS dark mode. Is there a way to override the default styling for that. I tried the following:

.date-picker {
   color: #000000;

   .ns-dark & {
     color: #000000;
   }
}

在此处输入图片说明

This is how it looks when the background is black

Use UIUserInterfaceStyle property overrideUserInterfaceStyle of UIViewController to change controller's interface style.

class TestViewController: UIViewController {

    @IBOutlet weak var datePicker: UIDatePicker!

    override func viewDidLoad() {
        super.viewDidLoad()

        if #available(iOS 13.0, *) {
            overrideUserInterfaceStyle = .dark
            datePicker.backgroundColor = .black
        } else {
            datePicker.backgroundColor = .white
        }
    }
}

The problem was that I couldn't override the color of the Datepicker. I was also not able to override the background color of the modal. I needed to add the <page> tag to my modal. There I can add a class so I could change the background color during dark mode. So it looks something like this:

<Page class="background-color-modal">
    <DockLayout class="modal">
          <FlexboxLayout class="timeDateDetails">
               <time-modal :selected-time="selectedTime" 
                           :time="$props.time" @updateTime="updateTime"/>
          </FlexboxLayout>
     </DockLayout>
</Page>

<style lang="scss" scoped>

    .background-color-modal {
        background-color: $white;
        color: $dark;

        .ns-dark & {
            background-color: $dark-dark;
            color: $dark-white
        }
    }

    .modal {
        background-color: $white;
        color: $dark;

        .ns-dark & {
            background-color: $dark-dark;
            color: $dark-white
        }
    }
</style>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM