我有一個帶有自定義渲染器的 Shell Tabbar 和一個位于其后面的 Collection 視圖。現在,當我的收藏視圖中有位于標簽欄后面的內容時,標簽欄背景顏色會變白。
在
更重要的是,對您的代碼有一個小建議。
SetAppearance方法在切換時呼叫Tabbar,因此它不斷添加視圖。
應該只添加一次視圖,最好更改邏輯。
更新
UIView myView = null;
public void SetAppearance(UITabBarController controller, ShellAppearance appearance)
{
UITabBar myTabBar = controller.TabBar;
UIColor tabBarColor = UIColor.White; //to any color you want
if (myTabBar != null)
{
if (myView != null) return;
myView = new UIView(new CGRect(0, 0, myTabBar.Frame.Width, 2)) { BackgroundColor = Color.FromRgb(17, 17, 17).ToUIColor() };
myTabBar.AddSubview(myView);
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);
}
}
}
}
uj5u.com熱心網友回復:
我現在解決了它,透明度的提示是正確的它只是不是顏色的透明度,我的標簽欄以某種方式設定為半透明
我的作業代碼:
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);
}
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/402246.html
標籤:ios 沙马林 xamarin.forms xamarin.ios
