UIView隐藏导航栏后退按钮文本如何使其可见? [英] UIView hides Navigation bar back button text how to make it visible?
本文介绍了UIView隐藏导航栏后退按钮文本如何使其可见?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将导航栏背景更改为渐变红色。
我已将子视图添加到导航栏,它将背景设置为我想要的颜色。
然后导航栏后退按钮文本是不可见的。
后退按钮可见,但文字不可见。
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);
推荐答案
我用渐变色创建了图像并使用了该图像作为NavigationBar的背景。对于iOS,请参阅下面的教程。
I created image out of gradient color and used that image as Background to NavigationBar. For iOS see below tutorial.
UINavigationBar tintColor with渐变
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)
;
这篇关于UIView隐藏导航栏后退按钮文本如何使其可见?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文