Issue
I have a Shell Tabbar with a custom renderer and a Collection view that goes behind it. Now when there is content in my Collection view that is behind the tabbar, the tabbar background color whitens.
before enter image description here after enter image description here
I tried turning my custom renderer off and it worked as expected and there are no color changes, so I know that it is in my custom renderer but I can't figure out what it is.
Custom Renderer:
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)
{
}
}
Solution
I now solved it, the hint with the transparency was right it just wasn't the transparency of the color, my tabbar was somehow set to translucent
my working code:
UIView myView = null;
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)
{
myView = new UIView(new CGRect(0, 0, myTabBar.Frame.Width, 2)) { BackgroundColor = Color.FromRgb(17, 17, 17).ToUIColor() };
myTabBar.AddSubview(myView);
myTabBar.BackgroundColor = tabBarColor;
myTabBar.BarTintColor = tabBarColor;
myTabBar.Translucent = false;
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);
}
}
}
}
Answered By - Jeremiah
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.