如何更改辅助工具栏的背景颜色 - xamarin ios
问题描述:
使用
Navigation
渲染器我尝试通过设置以下内容来更改工具栏的背景颜色。如何更改辅助工具栏的背景颜色 - xamarin ios
this.Toolbar.BackgroundColor = Color.Yellow;
但我的辅助工具栏颜色没有变化。
任何人都可以让我知道如何更改Xamarin iOS中的辅助工具栏的背景颜色?
答
我做到了,通过以下方式:
[assembly: ExportRenderer(typeof(NavigationPage), typeof(ExtendedNavigationRenderer))]
namespace Sample.iOS
{
public class ExtendedNavigationRenderer : NavigationRenderer
{
UIToolbar _secondaryToolbar;
public override void ViewDidLoad()
{
base.ViewDidLoad();
//_secondaryToolbar = View.Subviews.OfType<UIToolbar>().FirstOrDefault(v => v.GetType() != typeof(UIToolbar));
_secondaryToolbar = View.Subviews.OfType<UIToolbar>().FirstOrDefault();
if (_secondaryToolbar != null)
_secondaryToolbar.BarTintColor = this.NavigationBar.BarTintColor;
}
public override void ViewDidLayoutSubviews()
{
base.ViewDidLayoutSubviews();
if (_secondaryToolbar != null && _secondaryToolbar.Items != null)
{
foreach (UIBarButtonItem item in _secondaryToolbar.Items)
{
var label = item.CustomView.Subviews.OfType<UILabel>().FirstOrDefault();
if (label != null)
{
label.TextColor = UINavigationBar.Appearance.TitleTextAttributes.ForegroundColor;
//label.Font = label.Font.WithSize(12f);
}
}
}
}
(TintColor做法带来的真正的颜色,是从主导航栏略有不同,但NavigationBar.BackgroundColor为null)
这是你在做什么寻找? https://developer.xamarin.com/recipes/ios/content_controls/navigation_controller/change_the_nav_bar_color/ – cvanbeek
我正在讨论辅助工具栏...您使用Order属性启用的工具栏: ToolbarItem> ToolbarItem> ToolbarItem> ToolbarItem> –
user3903423
什么是”工具栏“,是指自定义渲染器”NavigationRenderer“中的工具栏,还可以附加图像来描述您的问题,我认为它会更直观 –