zoukankan      html  css  js  c++  java
  • 仿美团下拉菜单DropDownMenu

    github 下载demo:https://github.com/MartinLi841538513/MartinDemos (一切以demo为准)

    1,下载好dropDownList库,拖到自己项目中。

    2,在.h文件中引入

    #import <UIKit/UIKit.h>
    #import "DropDownListView.h"
    #import "DropDownChooseProtocol.h"
    
    @interface DropDownDemoViewController : UIViewController<DropDownChooseDelegate,DropDownChooseDataSource>
    @property (weak, nonatomic) IBOutlet DropDownListView *dropDownView;
    @property (weak, nonatomic) IBOutlet NSLayoutConstraint *dropDownViewHeight;
    @property(nonatomic,strong)NSArray *chooseArray;
    @end

    这里的dropDownView和dropDownViewHeight对应xib文件中得view和height,我都用箭头给你画好了。

    chooseArray是数据源,在.m文件中会赋值。

    3,在.m文件中赋值,以及设置dropDownView。这里注意,我是事先改过dropdownlist源代码的,我觉得我这样设计更合理,且更方便。而且可以结合autolayout使用,很爽。

    #import "DropDownDemoViewController.h"
    
    @interface DropDownDemoViewController ()
    
    @end
    
    @implementation DropDownDemoViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view from its nib.
        self.chooseArray = [NSMutableArray arrayWithArray:@[
                                                       @[@"童明城",@"童赟",@"童林杰",@"老萧狗"],
                                                       @[@"郏童熙",@"胥童嘉",@"郑嘉琦"]
                                                       ]];
        self.dropDownView.dropDownDataSource = self;
        self.dropDownView.dropDownDelegate = self;
        self.dropDownView.height = self.dropDownViewHeight.constant;
        [self.dropDownView setView];
        self.dropDownView.mSuperView = self.view;
    }
    
    
    #pragma mark -- dropDownListDelegate
    -(void) chooseAtSection:(NSInteger)section index:(NSInteger)index
    {
        NSLog(@"童大爷选了section:%d ,index:%d",section,index);
    }
    
    #pragma mark -- dropdownList DataSource
    -(NSInteger)numberOfSections
    {
        return [self.chooseArray count];
    }
    -(NSInteger)numberOfRowsInSection:(NSInteger)section
    {
        NSArray *arry =self.chooseArray[section];
        return [arry count];
    }
    -(NSString *)titleInSection:(NSInteger)section index:(NSInteger) index
    {
        return self.chooseArray[section][index];
    }
    -(NSInteger)defaultShowSection:(NSInteger)section
    {
        return 0;
    }
    @end

    这里是另外一个,有三级目录,效果更好,更新于2015年3月1日。

    http://code.cocoachina.com/detail/284158/%E7%B1%BB%E4%BC%BC%E7%BE%8E%E5%9B%A2%E7%9A%84%E4%B8%8B%E6%8B%89%E8%8F%9C%E5%8D%95/

  • 相关阅读:
    在线报表设计实战系列 – 制作动态列与静态列混排的报表(5)
    在线报表设计实战系列 – 制作复杂表头报表(4)
    在线报表设计实战系列 – 制作交叉分析表(3)
    在线报表设计实战系列 – 制作表格类报表(2)
    在线报表设计实战系列 – 准备数据源(1)
    ActiveReports 报表控件V12新特性 -- RPX报表转换为RDL报表
    ActiveReports 报表控件V12新特性 -- 新增矩表的RepeatToFill属性
    HDU 2199 Can you solve this equation?_二分搜索
    POJ 1606 jugs(又是水壶问题)
    POJ 3414 Pots
  • 原文地址:https://www.cnblogs.com/MartinLi841538513/p/4165938.html
Copyright © 2011-2022 走看看