Có rất nhiều cocoacontrols để thực hiện chức năng này trong ứng dụng của bạn:
DropDown Menu Controls For iOS
Nhưng tôi nghĩ lmdropdownview là chính xác nhất.
Lỗi của tôi, btnavigationdropdownmenu ITS chính xác nhất cho những gì bạn đang yêu cầu (theo màn hình của bạn).
thực hiện (Swift) [Xem readme để được hướng dẫn speceific hơn, và tùy biến]:
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]
}
Hy vọng nó giúp.
EDIT:
Cám ơn 'rsc' for the info, theres một objective-c version của cocoacontrol này:
#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;
}
Nguồn
2015-07-24 19:04:56
Điều này có vẻ siêu, cảm ơn bạn! – TheBrownCoder
https://github.com/qmathe/DropDownMenuKit –
https://github.com/PerfectFreeze/PFNavigationDropdownMenu - Biến thể mục tiêu-C của BTNavigationDropdownMenu – rsc