UIView hides Navigation bar back button text how to make it visible?

青春壹個敷衍的年華 提交于 2019-12-13 02:04:26

问题


I am trying to change Navigation bar background to Gradient Red. I have added subview to navigation bar which sets background to Color I want. but then Navigation bar back button Text is invisible. Back button is visible but Text is not Visible.

UIView view = new UIView();
var gradient = new CAGradientLayer();
gradient.Frame = NavigationBar.Bounds;
gradient.NeedsDisplayOnBoundsChange = true;
gradient.MasksToBounds = true;
gradient.Colors = new CGColor[] { UIColor.FromRGB(248, 0, 0).CGColor, UIColor.FromRGB(143, 0, 0).CGColor };
view.Layer.InsertSublayer(gradient, 0);
UINavigationBar.Appearance.SetTitleTextAttributes(new UITextAttributes() { TextColor = UIColor.Clear });

var bounds = NavigationBar.Bounds;
this.NavigationBar.AddSubview(view);

回答1:


I created image out of gradient color and used that image as Background to NavigationBar. For iOS see below tutorial.

UINavigationBar tintColor with gradient

           UIGraphics.BeginImageContext(gradient.Bounds.Size);
           gradient.RenderInContext(UIGraphics.GetCurrentContext());
           UIImage backImage = Graphics.GetImageFromCurrentImageContext();
           UIGraphics.EndImageContext();      
           NavigationBar.BarStyle = UIBarStyle.Default;
           UINavigationBar.Appearance.SetBackgroundImage(backImage, UIBarMetrics.Default);


来源:https://stackoverflow.com/questions/30701578/uiview-hides-navigation-bar-back-button-text-how-to-make-it-visible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!