[英]Tabs are hiding icons for child pages iOS TabbedRenderer
我正在使用Xamarin.Forms TabbedRenderer
在iOS中實現選項卡。 但是選項卡在移動到子頁面后會隱藏圖標。
下面是我的代碼
public class CustomTabRenderer_iOS : TabbedRenderer
{
public override void ViewWillLayoutSubviews()
{
base.ViewWillLayoutSubviews();
foreach (var item in TabBar.Items)
{
item.Image = GetTabIcon(item.Title);
}
}
private UIImage GetTabIcon(string title)
{
UITabBarItem item = null;
switch (title)
{
case "Dairy":
item = new UITabBarItem("Dairy", UIImage.FromFile("dairy"), 0);
break;
case "My kid":
item = new UITabBarItem("My kid",UIImage.FromFile("kid"),0);
break;
case "Events":
item = new UITabBarItem("Events", UIImage.FromFile("events"), 0);
break;
case "About":
item = new UITabBarItem("About", UIImage.FromFile("about"), 0);
break;
}
var img = (item != null) ? UIImage.FromImage(item.SelectedImage.CGImage, item.SelectedImage.CurrentScale, item.SelectedImage.Orientation) : new UIImage();
return img;
}
}
這是Attendance.xaml頁面
<?xml version="1.0" encoding="utf-8" ?>
<Shared:CToolbarPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="edTheSIS.Pages.Attendance"
Title="My Kid"
Icon="kid"
xmlns:Shared="clr-namespace:edTheSIS.Shared;assembly=edTheSIS">
<ContentPage.Content>
<StackLayout>
<Label Text="This is attendance..!"
</StackLayout>
</ContentPage.Content>
</Shared:CToolbarPage>
出席按鈕下方的點擊事件
private async void CreateTabs()
{
var tp = new MyTabbedPage();
tp.Children.Add(new DairyTabPage());
tp.Children.Add(new Attendance());
tp.Children.Add(new Events());
tp.Children.Add(new About());
tp.CurrentPage = tp.Children[1];
await Navigation.PushAsync(tp);
}
有關更多信息,請參見下面的輸出屏幕截圖,其中“我的孩子”標簽圖標未顯示
可能是我遇到的問題,在子頁面中,我沒有設置正確的標題 ,並且僅基於標題圖標進行了設置。 在下面的方法
private UIImage GetTabIcon(string title)
{
UITabBarItem item = null;
switch (title)
{
case "Dairy":
item = new UITabBarItem("Dairy", UIImage.FromFile("dairy"), 0);
break;
case "My kid":
item = new UITabBarItem("My kid",UIImage.FromFile("kid"),0);
break;
}
var img = (item != null) ? UIImage.FromImage(item.SelectedImage.CGImage, item.SelectedImage.CurrentScale, item.SelectedImage.Orientation) : new UIImage();
return img;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.