【问题标题】:Xamarin.Forms customizing action bar on iOSXamarin.Forms 在 iOS 上自定义操作栏
【发布时间】:2016-05-02 22:29:46
【问题描述】:

我正在使用 Xamarin.Forms,在 iOS 上我需要自定义顶部操作栏。 在这种情况下,我需要删除顶部操作栏和下面的内容视图之间的黑线(参见屏幕截图)。 我该怎么做?

提前谢谢你!!

我在这里做了,它工作正常:

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            //Tab bar
            UITabBar.Appearance.SelectedImageTintColor = UIColor.FromRGB(247, 139, 43); 
            //Switch
            UISwitch.Appearance.OnTintColor = UIColor.FromRGB(247, 139, 43);
            //----------------------------------------------------------------------------
            UINavigationBar.Appearance.BarTintColor = UIColor.Clear;
            UINavigationBar.Appearance.ShadowImage = new UIImage();
            UINavigationBar.Appearance.SetBackgroundImage(new UIImage(), UIBarMetrics.Default);
            //----------------------------------------------------------------------------                    
            global::Xamarin.Forms.Forms.Init();            
            ImageCircleRenderer.Init();                 
            LoadApplication(new App());

            return base.FinishedLaunching(app, options);
        }  

【问题讨论】:

  • 刚刚完成,非常感谢!

标签: xamarin xamarin.ios xamarin.forms


【解决方案1】:

您可以通过创建自定义渲染器来实现此目的:

[assembly: ExportRenderer(typeof(CustomNavigationPage), typeof(CustomNavigationRenderer))]
    namespaceiOS.Renderers
    {
        public class CustomNavigationRenderer : NavigationRenderer
        {

            public override void ViewDidLoad()
            {
                base.ViewDidLoad();

                this.NavigationBar.ShadowImage = new UIImage();
                this.NavigationBar.SetBackgroundImage(new UIImage(), UIBarMetrics.Default);
             }
          }
     }

或者在您的 iOS 项目中,在 AppDelegate 方法“FinishedLaunching”中,您可以使用UIAppearance API 来全面设置您的应用程序的样式。

UINavigationBar.Appearance.ShadowImage = new UIImage();
UINavigationBar.Appearance.SetBackgroundImage(new UIImage(), UIBarMetrics.Default);

【讨论】:

  • 这是唯一的方法吗?我无法像在 Android 项目中那样在 Xamarin.iOS 项目上设置任何设置或样式?
  • 是的,它有帮助!正如我在上面的评论中发布的那样,我在 FinishedLaunching 内的 AppDelegate.cs 中完成了它并且它正在工作。可以吗,或者我必须在“DidFinishLaunching”中进行。如果是这种情况,您知道如何放入“DidFinishLaunching”吗?谢谢!!!
  • DidFinishLaunching 只是我的一个错字。我更新以反映正确的方法名称。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多