예제 #1
0
        public async Task <bool> IsLightOperatingSystemTheme()
        {
            if (UIDevice.CurrentDevice.CheckSystemVersion(12, 0))
            {
                UIViewController currentUIViewController = await GetVisibleViewController();

                UIUserInterfaceStyle userInterfaceStyle = currentUIViewController.TraitCollection.UserInterfaceStyle;

                switch (userInterfaceStyle)
                {
                case UIUserInterfaceStyle.Light:
                    return(true);

                case UIUserInterfaceStyle.Dark:
                    return(false);

                default:
                    return(true);
                }
            }
            else
            {
                return(true);
            }
        }
예제 #2
0
        public Theme GetOperatingSystemTheme()
        {
            UIViewController currentUIViewController = GetVisibleViewController();

            UIUserInterfaceStyle userInterfaceStyle = currentUIViewController.TraitCollection.UserInterfaceStyle;

            return(userInterfaceStyle switch
            {
                UIUserInterfaceStyle.Light => Theme.Light,
                UIUserInterfaceStyle.Dark => Theme.Dark,
                _ => throw new NotSupportedException($"UIUserInterfaceStyle {userInterfaceStyle} not supported"),
            });
예제 #3
0
        void SetOverrideUserInterfaceStyle(string themeName)
        {
            if (Control == null || !UIDevice.CurrentDevice.CheckSystemVersion(12, 0))
            {
                return;
            }
            UIUserInterfaceStyle userInterfaceStyle = themeName == "Light" ? UIUserInterfaceStyle.Light : UIUserInterfaceStyle.Dark;

            if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
            {
                Control.OverrideUserInterfaceStyle = userInterfaceStyle;
            }
        }