2016-11-06 10 views
0

の選択されていないアイコンの色をTabbedページから変更しようとしています。私が選択した項目のテキストの色と非選択項目のテキストの色ではなく、アイコンの色を変更するために管理しているXamarinフォームのタブ付きページタブ非選択色

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); 
     } 
    } 
} 

enter image description here

は、私は、カスタムTabbedRendererを持っています。

ありがとうございました!

+0

http://stackoverflow.com/questions/24526851/how-to-change-tabbar- icon-color-in-ios –

+0

有用ではありません。ありがとう! –

答えて

1
private void UpdateItem(UITabBarItem item, string icon) 
{ 
    if (item == null) 
     return; 
    try 
    { 
     string newIcon = icon.Replace(".png", " Filled.png"); 
     if (item == null) return; 
     if (item.SelectedImage == null) return; 
     if (item.SelectedImage.AccessibilityIdentifier == icon) return; 

     item.Image = UIImage.FromBundle(icon); 
     item.Image = item.Image.ImageWithRenderingMode(UIKit.UIImageRenderingMode.AlwaysOriginal); 

     item.SelectedImage = UIImage.FromBundle(newIcon); 
     item.SelectedImage = item.SelectedImage.ImageWithRenderingMode(UIKit.UIImageRenderingMode.AlwaysOriginal); 

     item.SelectedImage.AccessibilityIdentifier = icon; 
    } 
    catch (Exception ex) 
    { 
     Console.WriteLine("Unable to set selected icon: " + ex); 
    } 
} 
1

選択されていないアイコンの色: 非常に先頭またはあなたのViewWillAppearイベントでは、行を置く:

 TabBar.UnselectedItemTintColor = UIColor.Red; //red is for the yay effect :) 
+0

これは最新のXamarin.Formsパッケージに追加されました。私は質問を投稿すると2.3.3.193を走っていた。ありがとう! –