【发布时间】:2022-01-27 09:57:14
【问题描述】:
我有一个带有自定义渲染器的 Shell Tabbar 和一个位于它后面的 Collection 视图。 现在,当我的 Collection 视图中有内容位于标签栏后面时,标签栏背景颜色变白。
之前 enter image description here 后 enter image description here
我尝试关闭我的自定义渲染器,它按预期工作并且没有颜色变化,所以我知道它在我的自定义渲染器中,但我不知道它是什么。
自定义渲染器:
public class MyShellRenderer : ShellRenderer
{
protected override IShellSectionRenderer CreateShellSectionRenderer(ShellSection shellSection)
{
var renderer = base.CreateShellSectionRenderer(shellSection);
if (renderer != null)
{
}
return renderer;
}
protected override IShellTabBarAppearanceTracker CreateTabBarAppearanceTracker()
{
return new CustomTabbarAppearance();
}
}
public class CustomTabbarAppearance : IShellTabBarAppearanceTracker
{
public void Dispose()
{
}
public void ResetAppearance(UITabBarController controller)
{
}
public void SetAppearance(UITabBarController controller, ShellAppearance appearance)
{
UITabBar myTabBar = controller.TabBar;
UIColor tabBarColor = ((Xamarin.Forms.Color)Xamarin.Forms.Application.Current.Resources["MyTabBarColor"]).ToUIColor();
if (myTabBar != null)
{
UIView view = new UIView(new CGRect(0, 0, myTabBar.Frame.Width, 2)) { BackgroundColor = Color.FromRgb(17, 17, 17).ToUIColor() };
myTabBar.AddSubview(view);
myTabBar.BackgroundColor = tabBarColor;//change
myTabBar.BarTintColor = tabBarColor;
myTabBar.UnselectedItemTintColor = UIColor.White;
if (myTabBar.Items != null)
{
foreach (UITabBarItem item in myTabBar.Items)
{
item.Title = null;
item.ImageInsets = new UIEdgeInsets(10, 0, 0, 0);
}
}
}
}
public void UpdateLayout(UITabBarController controller)
{
}
}
【问题讨论】:
-
听起来标签栏背景颜色有一些透明度。直接在自定义渲染器中使用硬编码的背景颜色进行测试,看看是否可以让症状停止。
-
我已经在自定义渲染器中直接设置了背景颜色。但注意到当我移除 bartintcolor 时,它会变得更亮,所以我认为这与此有关。
-
这两者之间似乎有一些互动。谷歌
xamarin ios bartintcolor vs background color。很多讨论 - 我不知道其中任何一个是否“解决”它。
标签: ios xamarin xamarin.forms xamarin.ios