UISegmentedControl在iOS 7中的UINavigationbar下面 [英] UISegmentedControl below UINavigationbar in iOS 7

查看:107
本文介绍了UISegmentedControl在iOS 7中的UINavigationbar下面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将 UISegmentedControl 作为 UINavigationBar 的一部分下方呢?它是否连接到 UINavigationBar ,还是一个完整的单独视图,只是作为子视图添加到 UINavigationController 的视图中控制器。看起来它是 UINavigationBar 的一部分,因为栏下面有一个阴影。

How do I make a UISegmentedControl as a part of an UINavigationBar below it? Is it connected to the UINavigationBar or is it a complete separate view just added as a subview to the UINavigationController's view controller. Looks like it is part of the UINavigationBar since there is a shadow below the bar.

推荐答案

这是一个简单的效果。

首先,将一个片段放在工具栏中。将此工具栏放在导航栏的正下方。将工具栏的委托设置为视图控制器,并在 positionForBar:中返回 UIBarPositionTopAttached 。您可以在商店应用中看到,如果您执行交互式弹出手势,则段栏的移动方式与导航栏不同。这是因为它们不是同一个栏。

First, place a segment in a toolbar. Place this toolbar right below the navigation bar. Set the delegate of the toolbar to your view controller, and return UIBarPositionTopAttached in positionForBar:. You can see in the store app, if you perform an interactive pop gesture, that the segment bar does not move the same as the navigation bar. That's because they are not the same bar.

现在删除发际线。 发际线是 UIImageView ,它是导航栏的子视图。您可以找到它并将其设置为隐藏。这就是Apple在其原生日历应用程序中所做的事情,以及商店应用程序。记得在当前视图消失时显示它。如果您使用Apple应用程序玩一点,您会看到发线设置为 viewWillAppear:,并设置为 viewDidDisappear:

Now to remove the hairline. The "hairline" is an 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, as well as the store app. Remember to show it when the current view disappears. If you play a little with the Apple apps, you will see that the hairline is set to hidden on viewWillAppear: and set to shown in viewDidDisappear:.

要实现搜索栏的样式,只需将栏的 searchBarStyle 设置为 UISearchBarStyleMinimal

To achieve the style of the search bar, just set the bar's searchBarStyle to UISearchBarStyleMinimal.

这篇关于UISegmentedControl在iOS 7中的UINavigationbar下面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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