精华内容
下载资源
问答
  • ios下拉菜单

    2013-03-26 10:52:41
    ios下拉菜单,下拉菜单可以拥有自己的一级子菜单。
  • iOS 下拉菜单

    2015-08-14 16:05:08
    一个简单的下拉菜单,想学习如何书写下拉菜单的同学,可以下载研究一下,整体还是挺简单的
  • IOS下拉菜单

    2015-11-10 18:54:29
    一个简单好用的下拉菜单,支持2级菜单,还有简单的动画效果哦!
  • ios 下拉菜单

    2015-08-04 11:46:05
    前段时间效果图做个下拉菜单,有个例子参照,分享给大家,同样也保存下来;
  • IOS 下拉菜单

    2015-10-30 17:58:00
    由于之前曾经用到过下拉菜单,所以现在花一些时间回过头来细细整理了一下,逐步完善这个下拉菜单,并提供一些比较基本的功能,以便日后如果有需要的话可以进行复用,并提供给需要的人参考。下拉菜单同样分为数据源和...

      由于之前曾经用到过下拉菜单,所以现在花一些时间回过头来细细整理了一下,逐步完善这个下拉菜单,并提供一些比较基本的功能,以便日后如果有需要的话可以进行复用,并提供给需要的人参考。下拉菜单同样分为数据源和代理方法,提供以下方法:

     1 //
     2 //  XWDropdownMenu.h
     3 // 4 //
     5 //  Created by xiao on 15/10/30.
     6 //  Copyright © 2015年 xiao. All rights reserved.
     7 //  下拉菜单
     8 
     9 #import <UIKit/UIKit.h>
    10 
    11 @class XWDropdownMenu;
    12 #pragma mark 数据源方法
    13 @protocol XWDropdownMenuDataSource <NSObject>
    14 @required
    15 /**
    16  *  主表格一共有多少行
    17  */
    18 - (NSInteger)numberOfRowsInMainTable:(XWDropdownMenu *)dropdownMenu;
    19 /**
    20  *  主表格每一行的标题
    21  *  @param row          行号
    22  */
    23 - (NSString *)dropdownMenu:(XWDropdownMenu *)dropdownMenu titleForRowInMainTable:(NSInteger)row;
    24 /**
    25  *  主表格每一行的子数据 根据数组显示子表每行内容
    26  *  @param row          主表行号
    27  */
    28 - (NSArray *)dropdownMenu:(XWDropdownMenu *)dropdownMenu subdataForRowInMainTable:(NSInteger)row;
    29 @optional
    30 /**
    31  *  主表格每一行 分类数量
    32  *  @param row          行号
    33  */
    34 - (NSString *)dropdownMenu:(XWDropdownMenu *)dropdownMenu countForRowInMainTable:(NSInteger)row;
    35 /**
    36  *  子表格每一行子数据 分类数量 根据数组显示子表每行提示数字
    37  *  @param row          主表行号
    38  */
    39 - (NSArray *)dropdownMenu:(XWDropdownMenu *)dropdownMenu subdataCountForRowInMainTable:(NSInteger)row;
    40 /**
    41  *  主表格每一行的图标
    42  *  @param row          行号
    43  */
    44 - (NSString *)dropdownMenu:(XWDropdownMenu *)dropdownMenu iconForRowInMainTable:(NSInteger)row;
    45 /**
    46  *  主表格每一行的选中图标
    47  *  @param row          行号
    48  */
    49 - (NSString *)dropdownMenu:(XWDropdownMenu *)dropdownMenu selectedIconForRowInMainTable:(NSInteger)row;
    50 @end
    51 
    52 #pragma mark 代理方法
    53 @protocol XWDropdownMenuDelegate <NSObject>
    54 
    55 @optional
    56 - (void)dropdownMenu:(XWDropdownMenu *)dropdownMenu didSelectRowInMainTable:(NSInteger)row;
    57 - (void)dropdownMenu:(XWDropdownMenu *)dropdownMenu didSelectRowInSubTable:(NSInteger)subrow inMainTable:(NSInteger)mainRow;
    58 
    59 @end
    60 
    61 #pragma mark 构造方法
    62 @interface XWDropdownMenu : UIView
    63 + (instancetype)dropdownMenu;
    64 -(void)refreshMenu;
    65 
    66 @property (nonatomic, weak) id<XWDropdownMenuDataSource> dataSource;
    67 @property (nonatomic, weak) id<XWDropdownMenuDelegate> delegate;
    68 
    69 /**主表被选中的字体颜色,默认是黑色*/
    70 @property (strong, nonatomic) UIColor *selectedRowTextColor;
    71 /**该属性设置成YES,主表较小*/
    72 @property (nonatomic, assign)BOOL isMainTableSmall;
    73 @end

     由于还是有一些代码的,无法在这里将所有代码贴出,只能罗列出各个方法并添加注释,并附上简单的demo和效果图

    demo地址:https://github.com/xiaoyeying/XWDropdownMenuDemo.git

     最后如有不足之处欢迎指正和批评,一起学习~~

    转载于:https://www.cnblogs.com/Lingchen-start/p/4923837.html

    展开全文
  • iOS下拉菜单 KSPopoverView ,KSPopoverView 是一个 iOS 的下拉菜单实现。
  • webapp模仿ios下拉菜单

    2019-08-10 01:39:53
    iosselect webapp模仿ios下拉菜单 html下拉菜单select在安卓和IOS下表现不一样,iosselect正是为统一下拉菜单样式而生 我们以IOS下select的交互和样式为蓝本,开发了这一组件 特点 可以做到0依赖,只需引用一个js和...
  • iOS 下拉菜单 REMenu.zip

    2019-09-17 19:58:04
    iOS 下拉菜单 REMenu ,REMenu 是 iOS 上一款下拉菜单,其灵感来自于 Vine
  • iOS 下拉菜单 NIDropDown ,NIDropDown 是 iOS 上的一个下拉菜单组件,类似 Web 上的下拉列表
  • iOS下拉菜单 PullDownMenu ,这是用于 iOS 上的一个下拉菜单控件,支持导航控制和视图,可直接下拉或者通过一个按钮触发。
  • iOS下拉菜单、下拉cell

    2016-09-13 16:22:59
    iOS下拉菜单,点击cell,下方插入一个cell。类似百度云文件夹操作。
  • 可定制的iOS下拉菜单.zip,iOS的下拉菜单,带有搜索和其他出色的定制功能
  • iOS 下拉菜单 Drop Down Menu ,DIYMenu 实现弹出下拉菜单效果。当点击菜单某个选项时,菜单又会收缩隐藏回去。具体效果请看视频。...
  • ios 下拉菜单 支持多选

    热门讨论 2012-09-13 09:33:29
    ios 下拉菜单 可以收缩 非常好
  • ios 下拉菜单Menu

    2020-11-04 15:22:33
    ios 下拉菜单Menu 1.手动封装一个下拉菜单,看了很多的demo,看到思路大致相同。手动写一个。 DropdownMenu.h #import <UIKit/UIKit.h> @class DropdownMenu; @protocol LHDropdownMenuDelegate <...

    ios 下拉菜单Menu

    看了很多的demo,看到思路大致相同。手动模仿写一个。

     

     DropdownMenu.h 

    #import <UIKit/UIKit.h>
    
    @class DropdownMenu;
    
    
    @protocol LHDropdownMenuDelegate <NSObject>
    @optional
    
    // 当选择某个选项时调用
    - (void)dropdownMenu:(DropdownMenu *)menu didSelectOptionAtIndex:(NSUInteger)index optionTitle:(NSString *)title;
    // 当下拉菜单将要显示时调用
    - (void)dropdownMenuWillShow:(DropdownMenu *)menu;
    // 当下拉菜单已经显示时调用
    - (void)dropdownMenuDidShow:(DropdownMenu *)menu;
    // 当下拉菜单将要收起时调用
    - (void)dropdownMenuWillHidden:(DropdownMenu *)menu;
    // 当下拉菜单已经收起时调用
    - (void)dropdownMenuDidHidden:(DropdownMenu *)menu;
    
    @end
    
    
    @protocol DropdownMenuDataSource <NSObject>
    
    @required
    /*
     list的内容代理
     */
    - (NSUInteger)numberOfOptionsInDropdownMenu:(DropdownMenu *)menu;
    
    - (CGFloat)dropdownMenu:(DropdownMenu *)menu heightForOptionAtIndex:(NSUInteger)index;
    
    - (NSString *)dropdownMenu:(DropdownMenu *)menu titleForOptionAtIndex:(NSUInteger)index;
    @optional
    - (UIImage *)dropdownMenu:(DropdownMenu *)menu iconForOptionAtIndex:(NSUInteger)index;
    @end
    @interface DropdownMenu : UIView<UITableViewDataSource,UITableViewDelegate>
    
    @property (nonatomic, weak) id <DropdownMenuDataSource> dataSource;
    @property (nonatomic, weak) id <LHDropdownMenuDelegate> delegate;
    
    /*
     
     Menu标题
     
     */
    
    //标题
    @property (nonatomic,copy)   NSString        * title;
    //背景色
    @property (nonatomic,strong) UIColor         * titleBgColor;
    //字体大小
    @property (nonatomic,strong) UIFont          * titleFont;
    //字体颜色
    @property (nonatomic,strong) UIColor         * titleColor;
    //文本的Alignment
    @property (nonatomic)        NSTextAlignment   titleAlignment;
    
    @property (nonatomic)        UIEdgeInsets      titleEdgeInsets;
    //图标
    @property (nonatomic,strong) UIImage         *  rotateIcon;
    //图标大小
    @property (nonatomic,assign) CGSize            rotateIconSize;
    //
    @property (nonatomic,assign) CGFloat           rotateIconMarginRight; // default: 7.5
    //图标的颜色
    @property (nonatomic,strong) UIColor         * rotateIconTint;
    
    /*
     -------list
     */
    //列表的颜色
    @property (nonatomic,strong) UIColor         * optionBgColor;
    //列表文本的大小
    @property (nonatomic,strong) UIFont          * listOptionFont;
    //列表文本的颜色
    @property (nonatomic,strong) UIColor         * listOptionTextColor;
    //列表文本的Alignment
    @property (nonatomic)        NSTextAlignment   listOptionTextAlignment;
    //列表文本的每行显示
    @property (nonatomic)        NSInteger         listOptionNumberOfLines;
    //列表的图标 default:(15,15)
    @property (nonatomic,assign) CGSize            listOptionIconSize;
    //列表图标右边距 default: 15
    @property (nonatomic,assign) CGFloat           listOptionIconMarginRight;
    //列表分割线的显色 default: white
    @property (nonatomic,strong) UIColor         * listOptionLineColor;
    //列表分割线导读 default: 0.5
    @property (nonatomic,assign) CGFloat           listOptionLineHeight;
    
    /*
     选项列表的最大高度。超出最大高度后,选项可滚动 (optionsListLimitHeight <= 0 时,下拉列表将显示所有选项)
     */
    @property (nonatomic,assign) CGFloat           optionsListLimitHeight; // default: 0
    @property (nonatomic,assign) BOOL              showsVerticalScrollIndicatorOfOptionsList; // default: YES
    
    // 下拉动画时间 default: 0.25
    @property (nonatomic,assign) CGFloat animateTime;
    
    
    - (void)reloadOptionsData;
    
    - (void)showDropDown; // 下拉菜单显示
    
    - (void)hideDropDown; // 下拉菜单隐藏
    
    @end

    DropdownMenu.m

    #import "DropdownMenu.h"
    
    @interface DropdownMenu() <UIGestureRecognizerDelegate>
    
    @property (nonatomic, strong) UIButton    *mainBtn;      // 菜单按钮
    @property (nonatomic, strong) UIImageView * arrowMark;    // 尖头图标
    @property (nonatomic, strong) UITableView *optionsList;  // 下拉列表
    @property (nonatomic, strong) UIView      *floatView;
    @property (nonatomic, strong) UIView      *coverView;
    
    @end
    
    @implementation DropdownMenu
    
    {
        BOOL _isOpened;
    }
    
    - (id)initWithFrame:(CGRect)frame{
        self = [super initWithFrame:frame];
        if (self) {
            [self initProperties];
            [self initViews];
            [self initFrame:self.frame];
        }
        return self;
    }
    
    - (void)awakeFromNib {
        [super awakeFromNib];
        [self initProperties];
        [self initViews];
        [self initFrame:self.frame];
    }
    
    - (void)layoutSubviews {
        if (_isOpened) return;
        CGFloat width  = self.frame.size.width;
        CGFloat height = self.frame.size.height;
        [_floatView setFrame:CGRectMake(_floatView.frame.origin.x, _floatView.frame.origin.y, width, height)];
        [_mainBtn setFrame:CGRectMake(0, 0, width, height)];
        [_arrowMark setFrame:CGRectMake(width -self.rotateIconMarginRight -self.rotateIconSize.width, (height -self.rotateIconSize.height)/2, self.rotateIconSize.width, self.rotateIconSize.height)];
        [_optionsList setFrame:CGRectMake(0, height, width, _optionsList.frame.size.height)];
    }
    
    #pragma mark - Init ,default默认
    - (void)initProperties{
        
        _title                  = @"Please Select";
        _titleBgColor           = [UIColor colorWithRed:64/255.f green:151/255.f blue:255/255.f alpha:1];
        _titleFont              = [UIFont boldSystemFontOfSize:15];
        _titleColor             = [UIColor whiteColor];
        _titleAlignment         = NSTextAlignmentLeft;
        _titleEdgeInsets        = UIEdgeInsetsMake(0, 10, 0, 10);
        
        _rotateIcon             = nil;
        _rotateIconSize         = CGSizeMake(15, 15);
        _rotateIconMarginRight  = 7.5;
        _rotateIconTint         = [UIColor blackColor];
        
        _optionBgColor          = [UIColor colorWithRed:64/255.f green:151/255.f blue:255/255.f alpha:0.5];
        _listOptionFont             = [UIFont systemFontOfSize:13];
        _listOptionTextColor        = [UIColor blackColor];
        _listOptionTextAlignment    = NSTextAlignmentCenter;
        _listOptionNumberOfLines    = 0;
        _listOptionIconSize         = CGSizeMake(0, 0);
        _listOptionIconMarginRight  = 15;
        _listOptionLineColor        = [UIColor whiteColor];
        _listOptionLineHeight       = 0.5f;
        
        _animateTime            = 0.25f;
        
        _optionsListLimitHeight = 0;
        
        _isOpened               = NO;
    }
    
    - (void)initViews{
        self.layer.masksToBounds = YES;
        
        _floatView = [[UIView alloc] initWithFrame:self.bounds];
        _floatView.layer.masksToBounds = YES;
        [self addSubview:_floatView];
        
        
        // 主按钮 显示在界面上的点击按钮
        _mainBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_mainBtn addTarget:self action:@selector(clickMainBtn:) forControlEvents:UIControlEventTouchUpInside];
        _mainBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _mainBtn.titleEdgeInsets            = UIEdgeInsetsMake(0, 15, 0, 0);
        _mainBtn.selected                   = NO;
        [_floatView addSubview:_mainBtn];
        
        // 旋转尖头
        _arrowMark = [[UIImageView alloc] init];
        [_arrowMark setTintColor:self.rotateIconTint];
        [_mainBtn addSubview:_arrowMark];
        
        
        // 下拉列表TableView
        _optionsList = [[UITableView alloc] init];
        _optionsList.delegate       = self;
        _optionsList.dataSource     = self;
        _optionsList.separatorStyle = UITableViewCellSeparatorStyleNone;
        _optionsList.scrollEnabled  = NO;
        [_floatView addSubview:_optionsList];
    }
    
    - (void)initFrame:(CGRect)frame {
        CGFloat width  = frame.size.width;
        CGFloat height = frame.size.height;
        [_floatView setFrame:CGRectMake(0, 0, width, height)];
        [_mainBtn setFrame:CGRectMake(0, 0, width, height)];
        [_arrowMark setFrame:CGRectMake(width -self.rotateIconMarginRight -self.rotateIconSize.width, (height -self.rotateIconSize.height)/2, self.rotateIconSize.width, self.rotateIconSize.height)];
        [_optionsList setFrame:CGRectMake(0, height, width, _optionsList.frame.size.height)];
    }
    
    #pragma mark - Action Methods
    - (void)reloadOptionsData{
        [self.optionsList reloadData];
    }
    - (void)clickMainBtn:(UIButton *)button{
        if(button.selected == NO) {
            [self showDropDown];
        }else {
            [self hideDropDown];
        }
    }
    
    - (void)showDropDown{   /* 显示下拉列表 */
        _isOpened = YES;
        // 变更menu图层
        CGPoint newPosition = [self getScreenPosition];
        _floatView.frame = CGRectMake(newPosition.x, newPosition.y, _floatView.bounds.size.width, _floatView.bounds.size.height);
        _floatView.layer.borderColor  = self.layer.borderColor;
        _floatView.layer.borderWidth  = self.layer.borderWidth;
        _floatView.layer.cornerRadius = self.layer.cornerRadius;
        [self.coverView addSubview:_floatView];
        
        // cell delegate
        if ([self.delegate respondsToSelector:@selector(dropdownMenuWillShow:)]) {
            [self.delegate dropdownMenuWillShow:self]; // 将要显示回调代理
        }
        
        // 刷新下拉列表数据
        [self reloadOptionsData];
        
        // 菜单高度计算
        CGFloat listHeight = 0;
        if (self.optionsListLimitHeight <= 0) { // 当未设置下拉菜单最小展示高度
            NSUInteger count = [self.dataSource numberOfOptionsInDropdownMenu:self];
            for (int i = 0; i < count; i++) {
                CGFloat cHeight = [self.dataSource dropdownMenu:self heightForOptionAtIndex:i];
                listHeight += cHeight;
            }
            _optionsList.scrollEnabled = NO;
        } else {
            listHeight = self.optionsListLimitHeight;
            _optionsList.scrollEnabled = YES;
        }
        
        // 执行展开动画
        __weak typeof(self) weakSelf = self;
        [UIView animateWithDuration:self.animateTime animations:^{
            UIView *floatView     = weakSelf.floatView;
            UIButton *mainBtn     = weakSelf.mainBtn;
            UITableView *listView = weakSelf.optionsList;
            
            floatView.frame = CGRectMake(floatView.frame.origin.x, floatView.frame.origin.y, floatView.frame.size.width, mainBtn.frame.size.height + listHeight);
            weakSelf.arrowMark.transform = CGAffineTransformMakeRotation(M_PI);
            listView.frame = CGRectMake(listView.frame.origin.x, listView.frame.origin.y, listView.frame.size.width, listHeight);
            
        }completion:^(BOOL finished) {
            if ([self.delegate respondsToSelector:@selector(dropdownMenuDidShow:)]) {
                [self.delegate dropdownMenuDidShow:self]; // 已经显示回调代理
            }
        }];
        
        _mainBtn.selected = YES;
    }
    
    
    - (void)hideDropDown{  // 隐藏下拉列表
        // call delegate
        if ([self.delegate respondsToSelector:@selector(dropdownMenuWillHidden:)]) {
            [self.delegate dropdownMenuWillHidden:self]; // 将要隐藏回调代理
        }
        
        // 执行关闭动画
        __weak typeof(self) weakSelf = self;
        [UIView animateWithDuration:self.animateTime animations:^{
            UIView *floatView = weakSelf.floatView;
            UIButton *mainBtn = weakSelf.mainBtn;
            weakSelf.arrowMark.transform = CGAffineTransformIdentity;
            weakSelf.floatView.frame  = CGRectMake(floatView.frame.origin.x, floatView.frame.origin.y, floatView.frame.size.width, mainBtn.frame.size.height);
            
        }completion:^(BOOL finished) {
            weakSelf.optionsList.frame = CGRectMake(weakSelf.optionsList.frame.origin.x, weakSelf.optionsList.frame.origin.y, weakSelf.frame.size.width, 0);
            
            // 变更menu图层
            weakSelf.floatView.frame = weakSelf.floatView.bounds;
            [self addSubview:weakSelf.floatView];
            [weakSelf.coverView removeFromSuperview];
            weakSelf.coverView = nil;
            
            self->_isOpened = NO;
            
            if ([self.delegate respondsToSelector:@selector(dropdownMenuDidHidden:)]) {
                [self.delegate dropdownMenuDidHidden:self]; // 已经隐藏回调代理
            }
        }];
        
        _mainBtn.selected = NO;
    }
    
    #pragma mark - Utility Methods
    - (CGPoint)getScreenPosition {
        return [self.superview convertPoint:self.frame.origin toView:[self getCurrentKeyWindow]];
    }
    
    - (UIWindow *)getCurrentKeyWindow {
        
        return [UIApplication sharedApplication].keyWindow;
    }
    
    #pragma mark - UITableView Delegate
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return [self.dataSource numberOfOptionsInDropdownMenu:self];
    }
    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
        return [self.dataSource dropdownMenu:self heightForOptionAtIndex:indexPath.row];
    }
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        static NSString *CellIdentifier = @"MenuOptionListCell";
        
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            //---------------------------下拉选项样式,可在此处自定义-------------------------
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
            cell.selectionStyle  = UITableViewCellSelectionStyleNone;
            cell.backgroundColor = self.optionBgColor;
            
            UILabel * titleLabel = [[UILabel alloc] init];
            titleLabel.font          = self.listOptionFont;
            titleLabel.textColor     = self.listOptionTextColor;
            titleLabel.numberOfLines = self.listOptionNumberOfLines;
            titleLabel.textAlignment = self.listOptionTextAlignment;
            titleLabel.tag           = 999;
            [cell addSubview:titleLabel];
            
            UIImageView * icon = [[UIImageView alloc] init];
            icon.tag = 888;
            [cell addSubview:icon];
            
            UIView * line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cell.frame.size.width, self.listOptionLineHeight)];
            line.backgroundColor = self.listOptionLineColor;
            line.tag             = 777;
            [cell addSubview:line];
        }
        CGFloat cHeight = [self.dataSource dropdownMenu:self heightForOptionAtIndex:indexPath.row];
        
        UILabel * titleLabel = [cell viewWithTag:999];
        titleLabel.text  = [self.dataSource dropdownMenu:self titleForOptionAtIndex:indexPath.row];;
        titleLabel.frame = CGRectMake(15, 0, self.frame.size.width - 15 -self.listOptionIconSize.width -self.listOptionIconMarginRight, cHeight);
        
        UIImageView * icon = [cell viewWithTag:888];
        if ([self.dataSource respondsToSelector:@selector(dropdownMenu:iconForOptionAtIndex:)]){
            icon.image = [self.dataSource dropdownMenu:self iconForOptionAtIndex:indexPath.row];
        }
        icon.frame = CGRectMake(self.frame.size.width -self.listOptionIconSize.width -self.listOptionIconMarginRight, (cHeight - self.listOptionIconSize.height)/2, self.listOptionIconSize.width, self.listOptionIconSize.height);
        
        UIView *line = [cell viewWithTag:777];
        line.frame           = CGRectMake(0, 0, cell.frame.size.width, self.listOptionLineHeight);
        line.backgroundColor = self.listOptionLineColor;
        
        return cell;
    }
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        UILabel * titleLabel = [cell viewWithTag:999];
        self.title = titleLabel.text;
        if ([self.delegate respondsToSelector:@selector(dropdownMenu:didSelectOptionAtIndex:optionTitle:)]) {
            [self.delegate dropdownMenu:self didSelectOptionAtIndex:indexPath.row optionTitle:titleLabel.text];
        }
        [self hideDropDown];
    }
    
    #pragma mark - UIGestureRecognizerDelegate
    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
        if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"]) {
            return NO;
        }
        return  YES;
    }
    
    
    #pragma mark - Get Methods
    - (BOOL)showsVerticalScrollIndicatorOfOptionsList {
        return _optionsList.showsVerticalScrollIndicator;
    }
    
    - (UIView *)coverView {
        UIWindow *window = [self getCurrentKeyWindow];
        if (_coverView == nil) {
            _coverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, window.bounds.size.width, window.bounds.size.height)];
            _coverView.backgroundColor = [UIColor clearColor];
            [window addSubview:_coverView];
            
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideDropDown)];
            tap.delegate = self;
            [_coverView addGestureRecognizer:tap];
        }
        return _coverView;
    }
    
    #pragma mark - Set Methods
    - (void)setFrame:(CGRect)frame {
        [super setFrame:frame];
        [self initFrame:frame];
    }
    
    - (void)setRotateIconSize:(CGSize)rotateIconSize {
        _rotateIconSize = rotateIconSize;
        [self.arrowMark setFrame:CGRectMake(self.mainBtn.bounds.size.width -self.rotateIconMarginRight -rotateIconSize.width, (self.mainBtn.bounds.size.height -rotateIconSize.height)/2, rotateIconSize.width, rotateIconSize.height)];
    }
    
    
    - (void)setRotateIcon:(UIImage *)rotateIcon {
        _rotateIcon = rotateIcon;
        [self.arrowMark setImage:rotateIcon];
    }
    
    - (void)setRotateIconMarginRight:(CGFloat)rotateIconMarginRight {
        _rotateIconMarginRight = rotateIconMarginRight;
        [self.arrowMark setFrame:CGRectMake(self.mainBtn.bounds.size.width -rotateIconMarginRight -self.rotateIconSize.width, (self.mainBtn.bounds.size.height -self.rotateIconSize.height)/2, self.rotateIconSize.width, self.rotateIconSize.height)];
    }
    - (void)setRotateIconTint:(UIColor *)rotateIconTint {
        _rotateIconTint = rotateIconTint;
        self.arrowMark.tintColor = rotateIconTint;
    }
    
    - (void)setTitle:(NSString *)title{
        _title = title;
        [self.mainBtn setTitle:title forState:UIControlStateNormal];
    }
    - (void)setTitleBgColor:(UIColor *)titleBgColor{
        _titleBgColor = titleBgColor;
        [self.mainBtn setBackgroundColor:titleBgColor];
        [self.arrowMark setBackgroundColor:titleBgColor];
    }
    - (void)setTitleFont:(UIFont *)titleFont{
        _titleFont = titleFont;
        self.mainBtn.titleLabel.font = titleFont;
    }
    - (void)setTitleColor:(UIColor *)titleColor{
        _titleColor = titleColor;
        [self.mainBtn setTitleColor:titleColor forState:UIControlStateNormal];
    }
    - (void)setTitleAlignment:(NSTextAlignment)titleAlignment{
        _titleAlignment = titleAlignment;
        if (titleAlignment == NSTextAlignmentLeft) {
            self.mainBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        } else if (titleAlignment == NSTextAlignmentCenter) {
            self.mainBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        } else if (titleAlignment == NSTextAlignmentRight) {
            self.mainBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        }
    }
    
    
    - (void)setShowsVerticalScrollIndicatorOfOptionsList:(BOOL)showsVerticalScrollIndicatorOfOptionsList {
        _optionsList.showsVerticalScrollIndicator = showsVerticalScrollIndicatorOfOptionsList;
    }
    
    
    - (void)setTitleEdgeInsets:(UIEdgeInsets)titleEdgeInsets{
        _titleEdgeInsets = titleEdgeInsets;
        self.mainBtn.titleEdgeInsets = titleEdgeInsets;
    }
    
    
    
    
    /*
    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    - (void)drawRect:(CGRect)rect {
        // Drawing code
    }
    */
    
    @end

     

     

     

    在需要的文件里添加并遵循代理<DropdownMenuDataSource,LHDropdownMenuDelegate>

    /*
    
    创建菜单数组及设置
    */
    - (void)viewDidLoad
    {
     _menu1OptionTitles = @[@"Option1",@"Option2",@"Option3",@"Option4",@"Option5"];
        
        menu1 = [[DropdownMenu alloc] init];
        [menu1 setFrame:CGRectMake(20, 120, 100, 30)];
        menu1.dataSource = self;
        menu1.delegate   = self;
        menu1.title           = @"Please";
        menu1.titleBgColor    = [UIColor colorWithRed:64/255.f green:151/255.f blue:255/255.f alpha:1];
        [self.view addSubview:menu1];
    
    }
    
    
    #pragma mark - DropdownMenu DataSource
    - (NSUInteger)numberOfOptionsInDropdownMenu:(DropdownMenu *)menu{
        
        return _menu1OptionTitles.count;
        
    }
    - (CGFloat)dropdownMenu:(DropdownMenu *)menu heightForOptionAtIndex:(NSUInteger)index{
        
        return 30;
        
    }
    - (NSString *)dropdownMenu:(DropdownMenu *)menu titleForOptionAtIndex:(NSUInteger)index{
        
        return _menu1OptionTitles[index];
        
    }
    - (UIImage *)dropdownMenu:(DropdownMenu *)menu iconForOptionAtIndex:(NSUInteger)index{
        
        return [UIImage imageNamed:_menu1OptionTitles[index]];
        
    }
    
    
    #pragma mark - LMJDropdownMenu Delegate
    - (void)dropdownMenu:(DropdownMenu *)menu didSelectOptionAtIndex:(NSUInteger)index optionTitle:(NSString *)title{
        
        NSLog(@"你选择了(you selected):menu1,index: %ld - title: %@", index, title);
        
    }
    
    - (void)dropdownMenuWillShow:(DropdownMenu *)menu{
        
        NSLog(@"--将要显示");
        
    }
    - (void)dropdownMenuDidShow:(DropdownMenu *)menu{
        
        NSLog(@"--已经显示");
        
    }
    
    - (void)dropdownMenuWillHidden:(DropdownMenu *)menu{
        
        NSLog(@"--将要隐藏");
        
    }
    - (void)dropdownMenuDidHidden:(DropdownMenu *)menu{
        
        NSLog(@"--已经隐藏");
        
    }

     

    展开全文
  • YNDropDownMenu 采用Swift3开发的可爱iOS下拉菜单
  • 支持搜索和其他很棒定制的iOS下拉菜单
  • 实现iOS下拉菜单的实现,有注释,便于自定义菜单,简单、实用
  • DropDownMenu, iOS下拉菜单,也可以实现类似NSComboBox的效果
  • IGLDropDownMenu, 带有漂亮动画和易于定制的iOS下拉菜单 IGLDropDownMenuiOS下拉菜单,动画效果不错。屏幕截图 :如何使用使用 CocoaPods:pod'igldropdownmenu'手动安装:只需将文件夹IGLDropDownMenu中的文件drap...
  • ios-IOS下拉菜单.zip

    2019-07-11 19:49:56
    行代码使实现下拉菜单 【Usage】 NSArray *items = @[@"东方不败", @"步惊云", @"女娲大帝"]; YHPullDownMenu *pd=[[YHPullDownMenu menuFrame:CGRectMake([UIScreen mainScreen].bounds.size.width-125-...
  • iOS下拉菜单效果实现

    2016-09-01 15:07:00
    iOS下拉菜单效果实现 简书主页:http://www.jianshu.com/users/37f2920f6848 Github主页:https://github.com/MajorLMJ iOS开发者公会-技术1群 QQ群号:87440292 iOS开发者公会-技术2群 QQ群号:232702419 ...

    原文链接:

    iOS下拉菜单效果实现

     


    简书主页:http://www.jianshu.com/users/37f2920f6848

    Github主页:https://github.com/MajorLMJ

    iOS开发者公会-技术1群 QQ群号:87440292

    iOS开发者公会-技术2群 QQ群号:232702419

    iOS开发者公会-议事区   QQ群号:413102158

    转载于:https://www.cnblogs.com/lmj123/p/5829969.html

    展开全文
  • 一个带有漂亮动画的iOS下拉菜单。 屏幕截图 如何使用 使用CocoaPods: pod'IGLDropDownMenu' 手动安装: 只需将文件夹IGLDropDownMenu中的文件拖放到您的项目中即可。 #### !尝试演示。 真的很有帮助! 样例...
  • 仿Ios下拉菜单

    2016-10-14 17:32:01
    仿ios 以及美团的单一下拉组件
  • iOS通过iOS进行下拉菜单下拉菜单这是一个支持iOS中的下拉菜单的Swift库在以下视频上观看视频:支持搜索和返回正确的索引自定义hideOp iOS通过iOS搜索的下拉菜单iOS中支持Swift下拉菜单观看视频:支持搜索并返回...
  • iOS 下拉菜单代码

    2015-12-04 20:50:34
    不错的资源,由于Demo过大不符合要求,所以只传片段代码
  • webapp模仿ios下拉菜单 html下拉菜单select在安卓和IOS下表现不一样,iosselect正是为统一下拉菜单样式而生 我们以IOS下select的交互和样式为蓝本,开发了这一组件 先看效果: 特点 可以做到0依赖,只需引用...

    github:https://github.com/zhoushengmufc/iosselect

    webapp模仿ios下拉菜单

    html下拉菜单select在安卓和IOS下表现不一样,iosselect正是为统一下拉菜单样式而生

    我们以IOS下select的交互和样式为蓝本,开发了这一组件

    先看效果:

    特点

    可以做到0依赖,只需引用一个js和css即可,样式可自己定制,也可使用默认样式

    文件说明

    src------iosselect基于iscroll5开发,在这个文件夹下可以看到iscroll.js,iosselect.js,iosselect.css,如果项目里有单独使用iscroll5,可以使用这个版本

    merge------合并了iscroll与iosselect,做到组件0依赖,方便开发

    demo------使用demo,说明如下:

    one------一级下拉菜单,以银行选择为实例
    
    two------二级下拉菜单,相互独立,没有关联,以三国杀组合选将为例
    
    three------三级下拉菜单,省市区选择三级联动
    
    rem------手机端部分解决方案会使用viewport缩放,这个时候我们需要添加一些样式,页面在缩放的情况下正常显示
    

    使用说明

    ###API
    new IosSelect(level, data, options)
    level: 选择的层级 1 2 3 最多支持3层
    data: [oneLevelArray[, twoLevelArray[, threeLevelArray]]]
    options:
         callback: 选择完毕后的回调函数 必选
         title: 选择框title  可选,没有此参数则不显示title
         itemHeight: 每一项的高度,可选,默认 35px
         headerHeight: 组件标题栏高度 可选,默认 44px
         addClassName: 组件额外类名 可选,用于自定义样式
         oneTwoRelation: 第一列和第二列是否通过parentId关联 可选,默认不关联
         twoThreeRelation: 第二列和第三列是否通过parentId关联 可选,默认不关联
         oneLevelId: 第一级选中id 可选
         twoLevelId: 第二级选中id 可选
         threeLevelId: 第三级选中id 可选
    ####参数说明
    level: 级联等级,支持1,2,3 必选项
    data: 数组,前三项分别对应级联1,2,3项,每一项又是一个数组,如果是一级下拉菜单,data长度为1
    
        每一项数组中包含一系列对象,每个对象必须要有id,作为该条数据在该项数组中的唯一标识,parentId是可选属性,作为关联的标志
    options.callback(selectOneObj[[, selectTwoObj], selectThreeObj]) 每个级联选中项,包含对应数据的所有字段及dom对象
    ####以地址选择为例:
    data为三个数组:
    // 省份列表
    var iosProvinces = [
        {'id': '130000', 'value': '河北省', 'parentId': '0'}
    ];
    
    // 城市列表
    var iosCitys = [
        {"id":"130100","value":"石家庄市","parentId":"130000"}
    ];
    
    // 区县列表
    var iosCountys = [
        {"id":"130102","value":"长安区","parentId":"130100"}
    ];
    实例化:
    var iosSelect = new IosSelect(3, 
            [iosProvinces, iosCitys, iosCountys],
            {
                title: '地址选择',
                itemHeight: 35,
                oneTwoRelation: 1,
                twoThreeRelation: 1,
                oneLevelId: oneLevelId,
                twoLevelId: twoLevelId,
                threeLevelId: threeLevelId,
                callback: function (selectOneObj, selectTwoObj, selectThreeObj) {
                    selectOneObj = {
                        atindex:26,
                        dom:li.at,
                        id:"510000",
                        parentid:"0",
                        value:"四川省"
                    }
                }
        });
    

    demo说明

    一级级联,银行选择

    http://zhoushengfe.com/iosselect/demo/one/bank.html

    二级级联,三国杀将领组合选

    http://zhoushengfe.com/iosselect/demo/two/sanguokill.html

    三级级联,省市区选择

    http://zhoushengfe.com/iosselect/demo/three/area.html

    viewport缩放时处理方案

    http://zhoushengfe.com/iosselect/demo/rem/bank.html

    转载于:https://www.cnblogs.com/mufc-go/p/5447100.html

    展开全文

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 490
精华内容 196
关键字:

ios下拉菜单