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/

  • 相关阅读:
    面向对象的继承关系体现在数据结构上时,如何表示
    codeforces 584C Marina and Vasya
    codeforces 602A Two Bases
    LA 4329 PingPong
    codeforces 584B Kolya and Tanya
    codeforces 584A Olesya and Rodion
    codeforces 583B Robot's Task
    codeforces 583A Asphalting Roads
    codeforces 581C Developing Skills
    codeforces 581A Vasya the Hipster
  • 原文地址:https://www.cnblogs.com/MartinLi841538513/p/4165938.html
Copyright © 2011-2022 走看看