设置非活动选项卡色调

时间:2018-04-24 08:16:31

标签: xamarin.ios

enter image description here

如何使用Xamarin.iOS设置非活动色调颜色?

Xcode有解决方案,但不能在Xamarin中使用它们。

1 个答案:

答案 0 :(得分:0)

对于底部文字

// This will change the text's color when the item is unselected
var attributes = new UITextAttributes();   
attributes.TextColor = UIColor.Red;
TabBarItem.SetTitleTextAttributes(attributes, UIControlState.Normal);

var selectedAttributes = new UITextAttributes();
selectedAttributes.TextColor = UIColor.White;
TabBarItem.SetTitleTextAttributes(selectedAttributes, UIControlState.Selected);

对于图标

// This will let the icon show the image's original color(instead of the gray) when the item is unselected
TabBarItem.Image = UIImage.FromBundle("imageName").ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);

选择项目时,您也可以使用相同的方法设置图像:

TabBarItem.SelectedImage = UIImage.FromBundle("imageName").ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);

或者只使用TabBar.TintColor = UIColor.White;