简体   繁体   中英

Xamarin iOS Transparent Navigation bar

Need to have transparent navigation bar

https://developer.xamarin.com/recipes/ios/content_controls/navigation_controller/change_the_nav_bar_transparency/
tried with this but not working.

Any Suggestion ?

Although, your question is not fully descriptive and not sure what exactly you want to achieve by saying "Not Working" from the given link.

Write following code in respective override methods of the ViewController in which you want to achieve the Transperent NavigationBar for that specific ViewController only.

public override void ViewWillAppear(bool animated)
{
    base.ViewWillAppear(animated);
    if (NavigationController != null)
    {
        NavigationController.NavigationBar.SetBackgroundImage(new UIImage(), UIBarMetrics.Default);
        NavigationController.NavigationBar.ShadowImage = new UIImage();
        NavigationController.NavigationBar.Translucent = true;
        NavigationController.View.BackgroundColor = UIColor.Clear;
        NavigationController.NavigationBar.BackgroundColor = UIColor.Clear;
    }
}

public override void ViewWillDisappear(bool animated)
{
    base.ViewWillDisappear(animated);
    if (NavigationController != null)
    {
        NavigationController.NavigationBar.SetBackgroundImage(null, UIBarMetrics.Default);
        NavigationController.NavigationBar.ShadowImage = null;
        NavigationController.NavigationBar.BarTintColor = UIColor.Red; //Provide your specific color here
    }
}

If you want to set this Globally, Try it in AppDelegate 's FinishedLaunching method :

UINavigationBar.Appearance.SetBackgroundImage(new UIImage(), UIBarMetrics.Default);
UINavigationBar.Appearance.ShadowImage = new UIImage();
UINavigationBar.Appearance.BackgroundColor = UIColor.Clear;
UINavigationBar.Appearance.Translucent = true;

Hope this helps!.

A single navigation bar is used for a particular navigation controller in iOS. So if you want to make it transparent for a single VC then you have to make it transparent when you navigate to that VC. And then change it back when you coming back from that VC in viewWillDisappear (or viewDidDisappear) methods.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM