fix: iOS tab icon issue
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
using System.Linq;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using CoreGraphics;
|
||||
using UIKit;
|
||||
using Xamarin.Forms;
|
||||
@ -100,14 +100,6 @@ 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)
|
||||
@ -119,6 +111,7 @@ namespace Pixiview.iOS.Renderers.AppShellSection
|
||||
tabBar.UnselectedItemTintColor = _defaultUnselectedTint;
|
||||
}
|
||||
|
||||
[SuppressMessage("Code Notifications", "XI0001:Notifies you with advices on how to use Apple APIs", Justification = "<Pending>")]
|
||||
public void SetAppearance(UITabBarController controller, ShellAppearance appearance)
|
||||
{
|
||||
IShellAppearanceElement appearanceElement = appearance;
|
||||
@ -127,33 +120,20 @@ namespace Pixiview.iOS.Renderers.AppShellSection
|
||||
var tintColor = appearanceElement.EffectiveTabBarForegroundColor; // appearanceElement.EffectiveTabBarTitleColor;
|
||||
|
||||
var tabBar = controller.TabBar;
|
||||
if (tabBar.Items != null && !initIcons)
|
||||
if (tabBar.Items != null && tabBar.Items.Length == 4)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
var tabUser = tabBar.Items[0];
|
||||
tabUser.Image = UIImage.FromBundle("IconUserRegular");
|
||||
tabUser.SelectedImage = UIImage.FromBundle("IconUser");
|
||||
var tabRecommend = tabBar.Items[1];
|
||||
tabRecommend.Image = UIImage.FromBundle("IconSparklesRegular");
|
||||
tabRecommend.SelectedImage = UIImage.FromBundle("IconSparkles");
|
||||
var tabRank = tabBar.Items[2];
|
||||
tabRank.Image = UIImage.FromBundle("IconSortRegular");
|
||||
tabRank.SelectedImage = UIImage.FromBundle("IconSort");
|
||||
var tabFavorite = tabBar.Items[3];
|
||||
tabFavorite.Image = UIImage.FromBundle("IconBookmarkRegular");
|
||||
tabFavorite.SelectedImage = UIImage.FromBundle("IconBookmark");
|
||||
}
|
||||
|
||||
if (_defaultTint == null)
|
||||
|
Reference in New Issue
Block a user