diff options
author | Samantha Houts <samantha@teamredwall.com> | 2016-04-18 09:46:51 -0700 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-04-18 09:46:51 -0700 |
commit | 75f112400223ea628ee008d311b7d5d54d98eafe (patch) | |
tree | af859c326a488cb0801fd57fca7bbce0cf0b4ad0 /Xamarin.Forms.Platform.iOS | |
parent | fc05a57e9dfa5b70e21b08f9c8f839b7986b4698 (diff) | |
download | xamarin-forms-75f112400223ea628ee008d311b7d5d54d98eafe.tar.gz xamarin-forms-75f112400223ea628ee008d311b7d5d54d98eafe.tar.bz2 xamarin-forms-75f112400223ea628ee008d311b7d5d54d98eafe.zip |
BarBackgroundColor and BarTextColor on TabbedPage (#96)
* [Core] Add properties to TabbedPage
* [Controls] Add properties to test page
* [iOS] Added BarBackgroundColor & BarTextColor to TabbedPage
* [A] Added BarBackgroundColor & BarTextColor to TabbedPage
* [UWP] Added BarBackgroundColor & BarTextColor to TabbedPage
* [WinRT] Format file
* [WinRT] Added BarBackgroundColor & BarTextColor to TabbedPage
* [Docs] Updated docs
Diffstat (limited to 'Xamarin.Forms.Platform.iOS')
-rw-r--r-- | Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs | 4 | ||||
-rw-r--r-- | Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs | 55 |
2 files changed, 57 insertions, 2 deletions
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs index f09fec9a..da3a0aa2 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/NavigationRenderer.cs @@ -594,6 +594,8 @@ namespace Xamarin.Forms.Platform.iOS { var titleAttributes = new UIStringAttributes(); titleAttributes.Font = globalAttributes.Font; + // TODO: the ternary if statement here will always return false because of the encapsulating if statement. + // What was the intention? titleAttributes.ForegroundColor = barTextColor == Color.Default ? titleAttributes.ForegroundColor ?? UINavigationBar.Appearance.TintColor : barTextColor.ToUIColor(); @@ -640,7 +642,7 @@ namespace Xamarin.Forms.Platform.iOS { containerController.NavigationItem.LeftBarButtonItem = new UIBarButtonItem(new UIImage(_parentMasterDetailPage.Master.Icon), UIBarButtonItemStyle.Plain, - (o, e) => _parentMasterDetailPage.IsPresented = !_parentMasterDetailPage.IsPresented); + (o, e) => _parentMasterDetailPage.IsPresented = !_parentMasterDetailPage.IsPresented); } catch (Exception) { diff --git a/Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs index 14bf4a24..2db8ac26 100644 --- a/Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs +++ b/Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs @@ -74,6 +74,9 @@ namespace Xamarin.Forms.Platform.iOS //disable edit/reorder of tabs CustomizableViewControllers = null; + UpdateBarBackgroundColor(); + UpdateBarTextColor(); + EffectUtilities.RegisterEffectControlProvider(this, oldElement, element); } @@ -227,7 +230,7 @@ namespace Xamarin.Forms.Platform.iOS void OnPropertyChanged(object sender, PropertyChangedEventArgs e) { - if (e.PropertyName == "CurrentPage") + if (e.PropertyName == nameof(TabbedPage.CurrentPage)) { var current = Tabbed.CurrentPage; if (current == null) @@ -239,6 +242,10 @@ namespace Xamarin.Forms.Platform.iOS SelectedViewController = controller; } + else if (e.PropertyName == TabbedPage.BarBackgroundColorProperty.PropertyName) + UpdateBarBackgroundColor(); + else if (e.PropertyName == TabbedPage.BarTextColorProperty.PropertyName) + UpdateBarTextColor(); } void Reset() @@ -292,6 +299,52 @@ namespace Xamarin.Forms.Platform.iOS Platform.SetRenderer(page, null); } + void UpdateBarBackgroundColor() + { + if (Tabbed == null || TabBar == null) + return; + + var barBackgroundColor = Tabbed.BarBackgroundColor; + + if (Forms.IsiOS7OrNewer) + { + TabBar.BarTintColor = barBackgroundColor == Color.Default ? UINavigationBar.Appearance.BarTintColor : barBackgroundColor.ToUIColor(); + } + else + { + TabBar.TintColor = barBackgroundColor == Color.Default ? UINavigationBar.Appearance.TintColor : barBackgroundColor.ToUIColor(); + } + } + + void UpdateBarTextColor() + { + if (Tabbed == null || TabBar == null || TabBar.Items == null) + return; + + var barTextColor = Tabbed.BarTextColor; + + var globalAttributes = UINavigationBar.Appearance.GetTitleTextAttributes(); + + var attributes = new UITextAttributes { Font = globalAttributes.Font }; + + if (barTextColor == Color.Default) + attributes.TextColor = globalAttributes.TextColor; + else + attributes.TextColor = barTextColor.ToUIColor(); + + foreach (UITabBarItem item in TabBar.Items) + { + item.SetTitleTextAttributes(attributes, UIControlState.Normal); + } + + // set TintColor for selected icon + // setting the unselected icon tint is not supported by iOS + if (Forms.IsiOS7OrNewer) + { + TabBar.TintColor = barTextColor == Color.Default ? UINavigationBar.Appearance.TintColor : barTextColor.ToUIColor(); + } + } + void UpdateChildrenOrderIndex(UIViewController[] viewControllers) { for (var i = 0; i < viewControllers.Length; i++) |