protected override void Dispose(bool disposing) { if (disposing) { _tabBarAppearance?.Dispose(); _tabBarAppearance = null; Page.SendDisappearing(); Tabbed.PropertyChanged -= OnPropertyChanged; Tabbed.PagesChanged -= OnPagesChanged; FinishedCustomizingViewControllers -= HandleFinishedCustomizingViewControllers; } base.Dispose(disposing); }
private void UpdateTabBarAppearance() { // https://developer.apple.com/forums/thread/682420 var deviceActionService = ServiceContainer.Resolve <IDeviceActionService>("deviceActionService"); if (deviceActionService.SystemMajorVersion() >= 15) { var appearance = new UITabBarAppearance(); appearance.ConfigureWithOpaqueBackground(); appearance.BackgroundColor = ThemeHelpers.TabBarBackgroundColor; appearance.StackedLayoutAppearance.Normal.IconColor = ThemeHelpers.TabBarItemColor; appearance.StackedLayoutAppearance.Normal.TitleTextAttributes = new UIStringAttributes { ForegroundColor = ThemeHelpers.TabBarItemColor }; TabBar.StandardAppearance = appearance; TabBar.ScrollEdgeAppearance = TabBar.StandardAppearance; } }
internal static void UpdateiOS15TabBarAppearance( this UITabBar tabBar, ref UITabBarAppearance _tabBarAppearance, UIColor?defaultBarColor, UIColor?defaultBarTextColor, Color?selectedTabColor, Color?unselectedTabColor, Color?barBackgroundColor, Color?barTextColor) { if (_tabBarAppearance == null) { _tabBarAppearance = new UITabBarAppearance(); _tabBarAppearance.ConfigureWithDefaultBackground(); } var effectiveBarColor = (barBackgroundColor == null) ? defaultBarColor : barBackgroundColor.ToPlatform(); // Set BarBackgroundColor if (effectiveBarColor != null) { _tabBarAppearance.BackgroundColor = effectiveBarColor; } // Set BarTextColor var effectiveBarTextColor = (barTextColor == null) ? defaultBarTextColor : barTextColor.ToPlatform(); if (effectiveBarTextColor != null) { _tabBarAppearance.StackedLayoutAppearance.Normal.TitleTextAttributes = new UIStringAttributes { ForegroundColor = effectiveBarTextColor }; } // Update colors for all variations of the appearance to also make it work for iPads, etc. which use different layouts for the tabbar // Also, set ParagraphStyle explicitly. This seems to be an iOS bug. If we don't do this, tab titles will be truncat... // Set SelectedTabColor if (selectedTabColor != null) { var foregroundColor = selectedTabColor.ToPlatform(); _tabBarAppearance.StackedLayoutAppearance.Selected.TitleTextAttributes = new UIStringAttributes { ForegroundColor = foregroundColor, ParagraphStyle = NSParagraphStyle.Default }; _tabBarAppearance.StackedLayoutAppearance.Selected.IconColor = foregroundColor; _tabBarAppearance.InlineLayoutAppearance.Selected.TitleTextAttributes = new UIStringAttributes { ForegroundColor = foregroundColor, ParagraphStyle = NSParagraphStyle.Default }; _tabBarAppearance.InlineLayoutAppearance.Selected.IconColor = foregroundColor; _tabBarAppearance.CompactInlineLayoutAppearance.Selected.TitleTextAttributes = new UIStringAttributes { ForegroundColor = foregroundColor, ParagraphStyle = NSParagraphStyle.Default }; _tabBarAppearance.CompactInlineLayoutAppearance.Selected.IconColor = foregroundColor; } else { var foregroundColor = UITabBar.Appearance.TintColor; _tabBarAppearance.StackedLayoutAppearance.Selected.TitleTextAttributes = new UIStringAttributes { ForegroundColor = foregroundColor, ParagraphStyle = NSParagraphStyle.Default }; _tabBarAppearance.StackedLayoutAppearance.Selected.IconColor = foregroundColor; _tabBarAppearance.InlineLayoutAppearance.Selected.TitleTextAttributes = new UIStringAttributes { ForegroundColor = foregroundColor, ParagraphStyle = NSParagraphStyle.Default }; _tabBarAppearance.InlineLayoutAppearance.Selected.IconColor = foregroundColor; _tabBarAppearance.CompactInlineLayoutAppearance.Selected.TitleTextAttributes = new UIStringAttributes { ForegroundColor = foregroundColor, ParagraphStyle = NSParagraphStyle.Default }; _tabBarAppearance.CompactInlineLayoutAppearance.Selected.IconColor = foregroundColor; } // Set UnselectedTabColor if (unselectedTabColor != null) { var foregroundColor = unselectedTabColor.ToPlatform(); _tabBarAppearance.StackedLayoutAppearance.Normal.TitleTextAttributes = new UIStringAttributes { ForegroundColor = foregroundColor, ParagraphStyle = NSParagraphStyle.Default }; _tabBarAppearance.StackedLayoutAppearance.Normal.IconColor = foregroundColor; _tabBarAppearance.InlineLayoutAppearance.Normal.TitleTextAttributes = new UIStringAttributes { ForegroundColor = foregroundColor, ParagraphStyle = NSParagraphStyle.Default }; _tabBarAppearance.InlineLayoutAppearance.Normal.IconColor = foregroundColor; _tabBarAppearance.CompactInlineLayoutAppearance.Normal.TitleTextAttributes = new UIStringAttributes { ForegroundColor = foregroundColor, ParagraphStyle = NSParagraphStyle.Default }; _tabBarAppearance.CompactInlineLayoutAppearance.Normal.IconColor = foregroundColor; } else { var foreground = UITabBar.Appearance.TintColor; _tabBarAppearance.StackedLayoutAppearance.Normal.TitleTextAttributes = new UIStringAttributes { ForegroundColor = foreground, ParagraphStyle = NSParagraphStyle.Default }; _tabBarAppearance.StackedLayoutAppearance.Normal.IconColor = foreground; _tabBarAppearance.InlineLayoutAppearance.Normal.TitleTextAttributes = new UIStringAttributes { ForegroundColor = foreground, ParagraphStyle = NSParagraphStyle.Default }; _tabBarAppearance.InlineLayoutAppearance.Normal.IconColor = foreground; _tabBarAppearance.CompactInlineLayoutAppearance.Normal.TitleTextAttributes = new UIStringAttributes { ForegroundColor = foreground, ParagraphStyle = NSParagraphStyle.Default }; _tabBarAppearance.CompactInlineLayoutAppearance.Normal.IconColor = foreground; } // Set the TabBarAppearance tabBar.StandardAppearance = tabBar.ScrollEdgeAppearance = _tabBarAppearance; }
void UpdateiOS15TabBarAppearance(UITabBarController controller, ShellAppearance appearance) { IShellAppearanceElement appearanceElement = appearance; var tabBar = controller.TabBar; var tabBarAppearance = new UITabBarAppearance(); tabBarAppearance.ConfigureWithOpaqueBackground(); // Set TabBarBackgroundColor var tabBarBackgroundColor = appearanceElement.EffectiveTabBarBackgroundColor; if (tabBarBackgroundColor != null) { tabBarAppearance.BackgroundColor = tabBarBackgroundColor.ToPlatform(); } // Set TabBarTitleColor var tabBarTitleColor = appearanceElement.EffectiveTabBarTitleColor; // Update colors for all variations of the appearance to also make it work for iPads, etc. which use different layouts for the tabbar // Also, set ParagraphStyle explicitly. This seems to be an iOS bug. If we don't do this, tab titles will be truncat... if (tabBarTitleColor != null) { tabBarAppearance.StackedLayoutAppearance.Normal.TitleTextAttributes = tabBarAppearance.StackedLayoutAppearance.Selected.TitleTextAttributes = new UIStringAttributes { ForegroundColor = tabBarTitleColor.ToPlatform(), ParagraphStyle = NSParagraphStyle.Default }; tabBarAppearance.StackedLayoutAppearance.Normal.IconColor = tabBarAppearance.StackedLayoutAppearance.Selected.IconColor = tabBarTitleColor.ToPlatform(); tabBarAppearance.InlineLayoutAppearance.Normal.TitleTextAttributes = tabBarAppearance.InlineLayoutAppearance.Selected.TitleTextAttributes = new UIStringAttributes { ForegroundColor = tabBarTitleColor.ToPlatform(), ParagraphStyle = NSParagraphStyle.Default }; tabBarAppearance.InlineLayoutAppearance.Normal.IconColor = tabBarAppearance.InlineLayoutAppearance.Selected.IconColor = tabBarTitleColor.ToPlatform(); tabBarAppearance.CompactInlineLayoutAppearance.Normal.TitleTextAttributes = tabBarAppearance.CompactInlineLayoutAppearance.Selected.TitleTextAttributes = new UIStringAttributes { ForegroundColor = tabBarTitleColor.ToPlatform(), ParagraphStyle = NSParagraphStyle.Default }; tabBarAppearance.CompactInlineLayoutAppearance.Normal.IconColor = tabBarAppearance.CompactInlineLayoutAppearance.Selected.IconColor = tabBarTitleColor.ToPlatform(); } //Set TabBarUnselectedColor var tabBarUnselectedColor = appearanceElement.EffectiveTabBarUnselectedColor; if (tabBarUnselectedColor != null) { tabBarAppearance.StackedLayoutAppearance.Normal.TitleTextAttributes = new UIStringAttributes { ForegroundColor = tabBarUnselectedColor.ToPlatform(), ParagraphStyle = NSParagraphStyle.Default }; tabBarAppearance.StackedLayoutAppearance.Normal.IconColor = tabBarUnselectedColor.ToPlatform(); tabBarAppearance.InlineLayoutAppearance.Normal.TitleTextAttributes = new UIStringAttributes { ForegroundColor = tabBarUnselectedColor.ToPlatform(), ParagraphStyle = NSParagraphStyle.Default }; tabBarAppearance.InlineLayoutAppearance.Normal.IconColor = tabBarUnselectedColor.ToPlatform(); tabBarAppearance.CompactInlineLayoutAppearance.Normal.TitleTextAttributes = new UIStringAttributes { ForegroundColor = tabBarUnselectedColor.ToPlatform(), ParagraphStyle = NSParagraphStyle.Default }; tabBarAppearance.CompactInlineLayoutAppearance.Normal.IconColor = tabBarUnselectedColor.ToPlatform(); } // Set TabBarDisabledColor var tabBarDisabledColor = appearanceElement.EffectiveTabBarDisabledColor; if (tabBarDisabledColor != null) { tabBarAppearance.StackedLayoutAppearance.Disabled.TitleTextAttributes = new UIStringAttributes { ForegroundColor = tabBarDisabledColor.ToPlatform(), ParagraphStyle = NSParagraphStyle.Default }; tabBarAppearance.StackedLayoutAppearance.Disabled.IconColor = tabBarDisabledColor.ToPlatform(); tabBarAppearance.InlineLayoutAppearance.Disabled.TitleTextAttributes = new UIStringAttributes { ForegroundColor = tabBarDisabledColor.ToPlatform(), ParagraphStyle = NSParagraphStyle.Default }; tabBarAppearance.InlineLayoutAppearance.Disabled.IconColor = tabBarDisabledColor.ToPlatform(); tabBarAppearance.CompactInlineLayoutAppearance.Disabled.TitleTextAttributes = new UIStringAttributes { ForegroundColor = tabBarDisabledColor.ToPlatform(), ParagraphStyle = NSParagraphStyle.Default }; tabBarAppearance.CompactInlineLayoutAppearance.Disabled.IconColor = tabBarDisabledColor.ToPlatform(); } tabBar.StandardAppearance = tabBar.ScrollEdgeAppearance = tabBarAppearance; }