如何去除 UINavigationBar 和 UISearchBar 细线 [英] How to remove UINavigationBar and UISearchBar hairline

查看:43
本文介绍了如何去除 UINavigationBar 和 UISearchBar 细线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 iOS 7 应用程序,我希望在其中的 NavigationBar 右侧有一个 SearchBar,并且我希望它们看起来像一个整体.因此,我需要用相同的颜色(已经完成)为它们着色,并删除 NavigationBar 底部和 SearchBar 顶部的细线.我怎样才能做到这一点?

I am creating an iOS 7 app in which I'd like to have a SearchBar right bellow the NavigationBar, and I wanted them both to look like a single piece. Therefore I need to tint them with the same color (done already) and remove that hairline at the bottom of the NavigationBar and at the top of the SearchBar. How can I achieve that?

推荐答案

官方来说,这只能通过将导航栏的 shadowImage 设置为空图像来实现.不过仔细看文档,据说:

Officially, this is only possible by setting the shadowImage of the navigationBar to an empty image. However, a closer look at the documentation, it is said:

要显示自定义阴影图像,还必须使用 setBackgroundImage:forBarMetrics: 方法设置自定义背景图像.如果使用默认背景图像,则无论此属性的值如何,都将使用默认阴影图像.

For a custom shadow image to be shown, a custom background image must also be set with the setBackgroundImage:forBarMetrics: method. If the default background image is used, then the default shadow image will be used regardless of the value of this property.

通过使用自定义背景图片,您将失去模糊的背景半透明度.

By using a custom background image, you would lose the blurred background translucency.

如果你喜欢冒险,发际线"是一个 UIImageView,它是导航栏的一个子视图.您可以找到它并将其设置为隐藏.例如,这就是 Apple 在其原生日历应用程序中所做的.记得在当前视图消失时显示它.

If you feel adventurous, the "hairline" is a UIImageView that is a subview of the navigation bar. You can find it and set it as hidden. This is what Apple does in their native calendar app, for example. Remember to show it when the current view disappears.

这篇关于如何去除 UINavigationBar 和 UISearchBar 细线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆