简体   繁体   English

透明的UINavigationBar无边框

[英]Transparent UINavigationBar without border

With iOS 7, it's now pretty easy to add a blur to UINavigationBar, even with a BarTint, see http://blog.ashleynh.me/frosted-uinavigationbar/ and this example image: 使用iOS 7,即使使用BarTint,现在也可以很轻松地向UINavigationBar添加模糊效果,请参见http://blog.ashleynh.me/frosted-uinavigationbar/以及以下示例图片:

在此处输入图片说明

However, there's a border at the bottom. 但是,底部有一个边框。 How can I get rid of the border to look more like this? 我如何摆脱边界看起来更像这样?

在此处输入图片说明

UPDATE : 更新

I took Danny and Shali's code, and here are the results. 我使用了Danny和Shali的代码,这是结果。 As you can see, the border doesn't show any more but there is no blur. 如您所见,边框不再显示,但没有模糊。

let navigationBarAppearance = UINavigationBar.appearance()
navigationBarAppearance.setBackgroundImage(UIImage(), forBarMetrics: UIBarMetrics.Default)
navigationBarAppearance.shadowImage = UIImage()
navigationBarAppearance.translucent = true

在此处输入图片说明

and here's the Inspector screenshot: 这是检查器的屏幕截图:

在此处输入图片说明

I also tried: 我也尝试过:

let navigationBarAppearance = UINavigationBar.appearance()
let clearImage = UIImage.imageWithColor(UIColor.clearColor())
navigationBarAppearance.setBackgroundImage(clearImage, forBarMetrics: UIBarMetrics.Default)
navigationBarAppearance.shadowImage = clearImage
navigationBarAppearance.translucent = true

Same result, but the Inspector is a little different: 结果相同,但检查器有所不同:

在此处输入图片说明

Apple Documents: https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UINavigationBar_Class/index.html#//apple_ref/occ/instp/UINavigationBar/shadowImage Apple文档: https : //developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UINavigationBar_Class/index.html#//apple_ref/occ/instp/UINavigationBar/shadowImage

The default value is nil, which corresponds to the default shadow image. 默认值为nil,它对应于默认的阴影图像。 When non-nil, this property represents a custom shadow image to show instead of the default. 如果为非零,则此属性表示要显示的自定义阴影图像,而不是默认图像。 For a custom shadow image to be shown, a custom background image must also be set with the setBackgroundImage:forBarMetrics: method. 为了显示自定义阴影图像,还必须使用setBackgroundImage:forBarMetrics:方法设置自定义背景图像。 If the default background image is used, then the default shadow image will be used regardless of the value of this property. 如果使用默认的背景图像,则无论此属性的值如何,都将使用默认的阴影图像。

So basically you need to set background image before setting shadowImage to make it work. 因此,基本上,您需要先设置背景图片,然后再设置shadowImage才能起作用。

Edit 编辑

Image generated from color (Swift) as background Navigation. 从颜色(快速)生成的图像作为背景导航。 Not sure if your blur function will still work when you change backgroundImage for Navigation bar. 不确定更改导航栏的backgroundImage时模糊功能是否仍然有效。 That would be a different problem. 那将是一个不同的问题。

class func imageWithColor(color: UIColor) -> UIImage {
    let rect = CGRectMake(0, 0, 1, 1)
    UIGraphicsBeginImageContextWithOptions(rect.size, false, 0)
    color.setFill()
    UIRectFill(rect)
    var image = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()

    return image
}

Have you tried navigationBar.shadowImage = [UIImage new]; 您是否尝试过navigationBar.shadowImage = [UIImage新]; ?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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