summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.iOS
diff options
context:
space:
mode:
authorSoftlion (Benjamin Mayrargue) <benjamin@mayrargue.com>2017-02-06 12:53:44 +0100
committerRui Marinho <me@ruimarinho.net>2017-02-06 11:53:44 +0000
commitc29403ac31aa689df97aa1d99c95e25d93c428c2 (patch)
treeff5759087fdd1514742400bbaf5348294c7d3be7 /Xamarin.Forms.Platform.iOS
parentbfb5de5676fd08059d4c86402ab89e7fa2376bd9 (diff)
downloadxamarin-forms-c29403ac31aa689df97aa1d99c95e25d93c428c2.tar.gz
xamarin-forms-c29403ac31aa689df97aa1d99c95e25d93c428c2.tar.bz2
xamarin-forms-c29403ac31aa689df97aa1d99c95e25d93c428c2.zip
TabbedRenderer / load icons from custom sources (from embbedded svg for example) (#574)
* Enable ios tab bar icons to be set by a custom renderer (using xamsvg for example) * Fix space => tabs * space => tabs / newline * space / newlines
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