iOS Quick Integration Search Interface drop-down menu frame

Source: Internet
Author: User

Objective

This launch of the control, more commonly used, 搜索界面下拉菜单 if you like my article, you can follow my microblog: Acridine a Zheng, can also come to small brother, learn about our iOS training courses. Follow up will also update more content, have any question, welcome 简书留言 Zheng Acridine ...

Demo Effect:
. Gifdemo Demo: 1. Create a drop-down menu
    YZPullDownMenu *menu = [[YZPullDownMenu alloc] init];    menu.frame = CGRectMake(0, 20, YZScreenW, 44);    [self.view addSubview:menu];
2. Setting the drop-down menu agent
menu.dataSource = self;
3. Add a sub-controller for all drop-down menus

为什么要这样设计?, because each app's drop-down menu is not deterministic, so it's up to each developer to decide on the drop-down menu interface.

- (void)setupAllChildViewController{    YZAllCourseViewController *allCourse = [[YZAllCourseViewController alloc] init];    YZSortViewController *sort = [[YZSortViewController alloc] init]; YZMoreMenuViewController *moreMenu = [[YZMoreMenuViewController alloc] init]; // 控制器最好作为自己的子控制器 [self addChildViewController:allCourse]; [self addChildViewController:sort]; [self addChildViewController:moreMenu];}
4. Implementing the Yzpulldownmenu Data source method
#pragma mark-yzpulldownmenudatasourceReturns the number of drop-down menu columns-(Nsinteger) Numberofcolsinmenu: (Yzpulldownmenu *) pulldownmenu{Return3;}Returns the drop-down menu for each column button-(UIButton *) Pulldownmenu: (Yzpulldownmenu *) Pulldownmenu Buttonforcolatindex: (Nsinteger) index{Yzmenubutton *button = [Yzmenubutton buttonwithtype:Uibuttontypecustom]; [Button Settitle:_titles[index] forstate:UIControlStateNormal]; [Button settitlecolor:[Uicolor Blackcolor] Forstate:UIControlStateNormal]; [Button settitlecolor:[Uicolor colorwithred:25/255.0 Green:143/255.0 Blue:238/255.0 Alpha:1] forstate:Uicontrolstateselected]; [Button setimage:[UIImage imagenamed:@ "label-down Arrow"] forstate:UIControlStateNormal]; [Button setimage:[UIImage imagenamed:@ "label-up Arrow"] forstate:Uicontrolstateselected];return button;}Returns the corresponding controller for each column in the drop-down menu-(Uiviewcontroller *) Pulldownmenu: (Yzpulldownmenu *) Pulldownmenu Viewcontrollerforcolatindex: (Nsinteger) index{ return self. Childviewcontrollers[index];} //Returns the height of each column of the drop-down menu-(cgfloat) Pulldownmenu: (Yzpulldownmenu *) Pulldownmenu heightforcolatindex: (Nsinteger) index{ //1th column height if (index = = 0) { return 400;} //2nd Column height if (index = = 1) { return 180;} //3rd column height return ;}              
5. "Update the menu title, you need to send a notification to me"

为什么要这样设计?Decoupling, your own controller does not need to import my frame's header file, the intrusion is not big.

"Update Menu title step"
    • 1. 【extern NSString * const YZUpdateMenuTitleNote;】 copy this line of code to your own controller, which is in YZPullDownMenu.h

    • 2. In the method of selecting the title, send the following notification
      [[Nsnotificationcenter Defaultcenter] postnotificationname:yzupdatemenutitlenote object:self userInfo:@{@ "title": Cell.textLabel.text}];

    • 3.1 postnotificationname: Notification name = =【YZUpdateMenuTitleNote】

    • 3.2 object: who sent the notification = "Self" (current controller)

    • 3.3 UserInfo: Check header information + can be multiple keys, multiple value, not fixed, because some interface, you need to tick a lot of options, key can be arbitrarily defined.

    • 3.4 The bottom level will automatically determine how many value of the current userinfo, if one will be directly updated menu title, there will be more updates to meet most requirements.

    • 3.5 notification will automatically bounce back drop-down menu

5.1 can refer to the code in Yzsortviewcontroller
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{    _selectedCol = indexPath.row;    // 选中当前 YZSortCell *cell = [tableView cellForRowAtIndexPath:indexPath]; // 更新菜单标题 [[NSNotificationCenter defaultCenter] postNotificationName:YZUpdateMenuTitleNote object:self userInfo:@{@"title":cell.textLabel.text}];}
Source

Click here to download the source code



Wen/Zheng (Jane book author)
Original link: http://www.jianshu.com/p/0e1bb29be42e
Copyright belongs to the author, please contact the author to obtain authorization, and Mark "book author".

iOS Quick Integration Search Interface drop-down menu frame

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.