【问题标题】:How to change the background color of secondary toolbar - xamarin ios如何更改辅助工具栏的背景颜色 - xamarin ios
【发布时间】:2017-09-26 04:07:43
【问题描述】:

Using Navigation renderer 我尝试通过设置以下内容来更改工具栏的背景颜色。

this.Toolbar.BackgroundColor = Color.Yellow;

但我的辅助工具栏颜色没有改变。

谁能告诉我如何更改 xamarin iOS 中辅助工具栏的背景颜色?

【问题讨论】:

  • 我说的是辅助工具栏...您使用 Order 属性启用的那个:
  • 什么是Toolbar,你的意思是自定义渲染器中的工具栏NavigationRenderer,还可以附上图片来描述你的问题,我觉得会更直观
  • @ColeXia 如果订单被指定为次要,则添加工具栏项目时..这些项目将添加到导航栏下方的辅助工具栏中..谢谢..我还添加了图像以供参考。
  • 你有没有找到答案?如果你这样做了,请告诉我

标签: xamarin xamarin.ios xamarin.forms toolbar navigationbar


【解决方案1】:

我是通过以下方式做到的:

[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略有不同,但NavigationBar.BackgroundColor为null)

【讨论】:

    猜你喜欢
    • 2016-04-21
    • 1970-01-01
    • 2016-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-31
    相关资源
    最近更新 更多