Forum Xamarin.iOS

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

How to toggle between Light & Dark Mode in Xamarin.iOS?

nantourakisnantourakis Member ✭✭

Most of the information I've found online is dealing with Xamarin Forms, Is it possible to toggle between Light & Dark Mode using only Xamarin.iOS?

I've added this piece of code to my ViewDidLoad Method in one of my controllers to change it to Dark Mode but I do not know how to toggle it back to Light mode if someone could please share some thoughts on how this could be done?

`public override void ViewDidLoad()
    {
        UILabel fetchDataLabel;
        UIView loadingView;

        **this.OverrideUserInterfaceStyle = UIUserInterfaceStyle.Dark;**

        base.ViewDidLoad();`

Answers

  • jezhjezh Member, Xamarin Team Xamurai

    I think you can check the official document : Dark Mode in Xamarin.iOS

    This article introduced Dark Mode for iOS and specifying images and colors for each mode using the asset catalog.

    Hope it can help you.

  • nantourakisnantourakis Member ✭✭

    Thank you for your help @jezh - I have an app already built where I would like to change the appearance from Light to Dark mode or vice versa depending on what the user chooses, is this currently possible in Xamarin.iOS?

  • JohnHJohnH GBMember ✭✭✭✭✭

    I created an option in our Xamarin.Forms app that allows the user to toggle from automatic, dark, and light mode in iOS, Android, UWP and Mac. But I effectively recreate the main page onwards.

  • JohnHJohnH GBMember ✭✭✭✭✭

    Here is the iOS specific code:

            var window = UIApplication.SharedApplication.Windows[0];
    
            switch (colorMode)
            {
                case ColorMode.LightMode:
                    window.OverrideUserInterfaceStyle = UIUserInterfaceStyle.Light;
                    break;
    
                case ColorMode.DarkMode:
                    window.OverrideUserInterfaceStyle = UIUserInterfaceStyle.Dark;
                    break;
    
                default:
                    window.OverrideUserInterfaceStyle = UIUserInterfaceStyle.Unspecified;
                    break;
            }
    
  • jezhjezh Member, Xamarin Team Xamurai

    Hi @nantourakis have you resolved your question?

Sign In or Register to comment.