【发布时间】:2019-09-27 12:13:15
【问题描述】:
我正在尝试更改 TabbedPage 中 未选择 图标的颜色。
我有一个自定义的 TabbedRenderer :
public class CustomTabbedPage : TabbedRenderer
{
public override void ViewWillAppear(bool animated)
{
if (TabBar == null) return;
if (TabBar.Items == null) return;
var tabs = Element as TabbedPage;
if (tabs != null)
{
for (int i = 0; i < TabBar.Items.Length; i++)
{
UpdateItem(TabBar.Items[i], tabs.Children[i].Icon);
}
}
base.ViewWillAppear(animated);
}
private void UpdateItem(UITabBarItem item, string icon)
{
if (item == null)
return;
try
{
icon = icon.Replace(".png", " Filled.png");
if (item == null) return;
if (item.SelectedImage == null) return;
if (item.SelectedImage.AccessibilityIdentifier == icon) return;
item.SelectedImage = UIImage.FromBundle(icon);
item.SelectedImage.AccessibilityIdentifier = icon;
}
catch (Exception ex)
{
Console.WriteLine("Unable to set selected icon: " + ex);
}
}
}
我已经设法更改了选定项的文本颜色和未选定项的文本颜色,但没有更改图标颜色。
谢谢!
【问题讨论】:
标签: c# xamarin xamarin.ios xamarin.forms