如何将下拉菜单添加到iOS中的导航栏标题
我想在这些屏幕截图中创建类似于下拉菜单的内容。 我该怎么做呢?
点击标题时,箭头指向上方,菜单会下降。 应用程序是大学菜单。
有很多cocoacontrols可以在你的应用程序中执行此function:
适用于iOS的DropDown菜单控件
但我认为lmdropdownview是最准确的。
我的错误, btnavigationdropdownmenu ITS最准确的你要问的(根据你的屏幕)。
实现(Swift)[有关更多特殊说明和自定义,请参阅自述文件]:
let items = ["Most Popular", "Latest", "Trending", "Nearest", "Top Picks"] let menuView = BTNavigationDropdownMenu(frame: CGRectMake(0.0, 0.0, 300, 44), title: items.first!, items: items, containerView: self.view) self.navigationItem.titleView = menuView menuView.didSelectItemAtIndexHandler = {(indexPath: Int) -> () in println("Did select item at index: \(indexPath)") self.selectedCellLabel.text = items[indexPath] }
希望能帮助到你。
编辑:
感谢’rsc’的信息,这是cocoacontrol的客观c版本 :
#import "PFNavigationDropdownMenu.h" -(void)viewDidLoad{ PFNavigationDropdownMenu *menuView = [[PFNavigationDropdownMenu alloc]initWithFrame:CGRectMake(0, 0, 300, 44)title:items.firstObjects items:items containerView:self.view]; menuView.didSelectItemAtIndexHandler = ^(NSUInteger indexPath){ NSLog(@"Did select item at index: %ld", indexPath); self.selectedCellLabel.text = items[indexPath]; }; self.navigationItem.titleView = menuView; }
如果您喜欢手动执行此操作,可能的解决方法
创建两个UIButton
(向上/向下),将第一个分配给navigationItem.titleView
,在此操作上添加UIControlEventTouchUpInside
操作,检查状态是否更改为展开或折叠并依赖于在UIViewController
view
顶部添加/删除带有空dataSource的UITableView
,设置适当的框架。 然后更新数据源并使用行动画UITableViewRowAnimationBottom
或UITableViewRowAnimationTop
重新加载,具体取决于它是否正在展开或折叠。 用第二个替换按钮。
- 自动布局不断拉伸UIImageView
- 如何检测NSURLConnection的sendSynchronousRequest:returningResponse:error:是否超时或其他错误
- Xcode服务器模拟器超时等待120秒
- 有没有一个iOS的等效appendBezierPathWithArcWithCenter
- 如何使用Facebook Graph API和facebook ios sdk获取完整的用户对象?
- NSDiacriticInsensitivePredicateOption不受Realm支持
- 使用未声明的标识符 – Xcode
- 从Any到Downcast协议
- 使用Jmeter代理来logging来自iOS模拟器的HTTP调用