[英]Removing of UINavigationBar border leads to black status bar
我试图删除下面的边界UINavigationBar
描述在这里 :
NavigationController.NavigationBar.SetBackgroundImage (new UIImage (), UIBarMetrics.Default);
NavigationController.NavigationBar.ShadowImage = new UIImage ();
在应用程序委托中,我还设置了背景色:
UINavigationBar.Appearance.BackgroundColor = UIColor.FromRGB (247, 247, 247);
现在, UINavigationBar
不再具有所需的边框,并且导航栏的颜色也已更改。 但是现在状态栏是完全黑色的,什么也没显示。 我试图在Info.plist中设置状态栏的样式,但这也没有帮助。
我做错了什么? 我是否必须以某种方式设置状态栏的背景?
现在,我尝试在一个单独的项目中执行此操作,并设置导航栏的背景色。 这里的状态栏不是黑色,但是状态栏的颜色消失了。 只有导航栏具有颜色,而状态栏保持为白色。 通常,通过设置条形颜色,状态栏和导航栏应具有相同的颜色。 例如
[[UINavigationBar appearance] setBarTintColor:[UIColor yellowColor]];
设置颜色条的颜色没有效果,因此我设置了导航条的背景色。
如何删除导航栏的边框并将状态栏和导航栏设置为相同的颜色?
我不记得我从哪里得到的,但是我认为它在obj-c中,这就是我使用的东西。
public static class UINavigationBarExtensions
{
public static void RemoveShadowImage(this UINavigationBar navigationBar)
{
foreach (var image in
from subView in navigationBar.Subviews
select subView as UIImageView
into imageView
where imageView != null && imageView.ToString()
.Contains("BarBackground")
from image in imageView.Subviews.OfType<UIImageView>()
.Where(image => Math.Abs(image.Bounds.Height - 0.5) < float.Epsilon)
select image)
image.RemoveFromSuperview();
}
}
由于其他方法未按预期工作,因此我现在创建了一个图像并将其设置为导航栏的背景,如下所示:
UIImage backgroundImage = ImageHelper.ImageWithColor (UINavigationBar.Appearance.BarTintColor, new CGRect (0, 0, 1, 1));
NavigationController.NavigationBar.SetBackgroundImage (backgroundImage, UIBarMetrics.Default);
NavigationController.NavigationBar.ShadowImage = new UIImage ();
这里是ImageHelper
类:
using System;
using System.Drawing;
using CoreGraphics;
using Foundation;
using UIKit;
public class ImageHelper
{
public ImageHelper ()
{
}
public static UIImage ImageWithColor(UIColor color, CGRect rect){
CGRect rectangleForImage = new CGRect (0, 0, rect.Width, rect.Height);
UIGraphics.BeginImageContext (rectangleForImage.Size);
CGContext context = UIGraphics.GetCurrentContext ();
context.SetFillColor (color.CGColor);
context.FillRect (rectangleForImage);
UIImage image = UIGraphics.GetImageFromCurrentImageContext ();
UIGraphics.EndImageContext ();
return image;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.