summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.iOS
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.iOS')
-rw-r--r--Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs32
1 files changed, 24 insertions, 8 deletions
diff --git a/Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs b/Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs
index 27492768..1470a934 100644
--- a/Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs
+++ b/Xamarin.Forms.Platform.iOS/Renderers/TabbedRenderer.cs
@@ -370,7 +370,8 @@ namespace Xamarin.Forms.Platform.iOS
void UpdateCurrentPage()
{
var count = ((IPageController)Tabbed).InternalChildren.Count;
- ((TabbedPage)Element).CurrentPage = SelectedIndex >= 0 && SelectedIndex < count ? Tabbed.GetPageByIndex((int)SelectedIndex) : null;
+ var index = (int)SelectedIndex;
+ ((TabbedPage)Element).CurrentPage = index >= 0 && index < count ? Tabbed.GetPageByIndex(index) : null;
}
void IEffectControlProvider.RegisterEffect(Effect effect)
@@ -384,17 +385,32 @@ namespace Xamarin.Forms.Platform.iOS
if(page == null)
throw new InvalidCastException($"{nameof(renderer)} must be a {nameof(Page)} renderer.");
- UIImage icon = null;
- if (!string.IsNullOrEmpty(page.Icon))
- icon = new UIImage(page.Icon);
-
- renderer.ViewController.TabBarItem = new UITabBarItem(page.Title, icon, 0)
+ var icons = GetIcon(page);
+ renderer.ViewController.TabBarItem = new UITabBarItem(page.Title, icons?.Item1, icons?.Item2)
{
Tag = Tabbed.Children.IndexOf(page),
AccessibilityIdentifier = page.AutomationId
};
-
- icon?.Dispose();
+ icons?.Item1?.Dispose();
+ icons?.Item2?.Dispose();
+ }
+
+ /// <summary>
+ /// Get the icon for the tab bar item of this page
+ /// </summary>
+ /// <returns>
+ /// A tuple containing as item1: the unselected version of the icon, item2: the selected version of the icon (item2 can be null),
+ /// or null if no icon should be set.
+ /// </returns>
+ protected virtual Tuple<UIImage, UIImage> GetIcon(Page page)
+ {
+ if (!string.IsNullOrEmpty(page.Icon))
+ {
+ var icon = new UIImage(page.Icon);
+ return Tuple.Create(icon, (UIImage)null);
+ }
+
+ return null;
}
}
} \ No newline at end of file