feature: custom dynamic tab icon
This commit is contained in:
@ -32,7 +32,7 @@ namespace Pixiview.iOS.Renderers
|
||||
|
||||
protected override IShellTabBarAppearanceTracker CreateTabBarAppearanceTracker()
|
||||
{
|
||||
return new AppShellTabBarAppearanceTracker();
|
||||
return new AppShellTabBarAppearanceTracker((AppShell)Element);
|
||||
}
|
||||
|
||||
protected override IShellNavBarAppearanceTracker CreateNavBarAppearanceTracker()
|
||||
|
@ -1,4 +1,5 @@
|
||||
using CoreGraphics;
|
||||
using System.Linq;
|
||||
using CoreGraphics;
|
||||
using UIKit;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Platform.iOS;
|
||||
@ -99,6 +100,14 @@ namespace Pixiview.iOS.Renderers.AppShellSection
|
||||
UIColor _defaultTint;
|
||||
UIColor _defaultUnselectedTint;
|
||||
|
||||
private readonly AppShell appShell;
|
||||
private bool initIcons;
|
||||
|
||||
public AppShellTabBarAppearanceTracker(AppShell shell)
|
||||
{
|
||||
appShell = shell;
|
||||
}
|
||||
|
||||
public void ResetAppearance(UITabBarController controller)
|
||||
{
|
||||
if (_defaultTint == null)
|
||||
@ -118,6 +127,34 @@ namespace Pixiview.iOS.Renderers.AppShellSection
|
||||
var tintColor = appearanceElement.EffectiveTabBarForegroundColor; // appearanceElement.EffectiveTabBarTitleColor;
|
||||
|
||||
var tabBar = controller.TabBar;
|
||||
if (tabBar.Items != null && !initIcons)
|
||||
{
|
||||
initIcons = true;
|
||||
var sources = appShell.CurrentItem.Items.Select(i => (FontImageSource)i.Icon).ToArray();
|
||||
var images = new UIImage[sources.Length];
|
||||
var handler = new FontImageSourceHandler();
|
||||
for (var i = 0; i < images.Length; i++)
|
||||
{
|
||||
var font = sources[i];
|
||||
if (font != null)
|
||||
{
|
||||
images[i] = handler.LoadImageAsync(new FontImageSource
|
||||
{
|
||||
FontFamily = "FontAwesome5Pro-Solid",
|
||||
Glyph = font.Glyph,
|
||||
Size = font.Size
|
||||
}).Result;
|
||||
}
|
||||
}
|
||||
for (var i = 0; i < tabBar.Items.Length; i++)
|
||||
{
|
||||
var image = images[i];
|
||||
if (image != null)
|
||||
{
|
||||
tabBar.Items[i].SelectedImage = image;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_defaultTint == null)
|
||||
{
|
||||
|
Reference in New Issue
Block a user