2016-11-06 2 views
0

Я пытаюсь изменить цвет unelected иконки из TabbedPage.Xamarin Forms TabbedPage Tab Unselected Color

enter image description here

У меня есть пользовательский TabbedRenderer:

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

я сумел изменить выбранный цвет элемента текста и цвет невыделенного элементов текста, но не значок цвет.

Спасибо!

+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

Unselected цвет значка: В самом начале или в вашем случае ViewWillAppear поставить строку:

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

Это было добавлено в последнем пакете Xamarin.Forms. Я задавал вопрос 2.3.3.193. Благодаря! –

Смежные вопросы