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); } }
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"), });
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; } }