AAMultiSelectController 0.5.0

AAMultiSelectController 0.5.0

测试已测试
Lang语言 Obj-CObjective C
许可 MIT
Released最后发布2017年2月

aozhimin维护。



  • dev-aozhimin

logo

概述

AAMultiSelectController提供了一个弹出对话框,用户可以进行多选操作。它易于使用并且可以轻松集成到您的项目中。

示例项目

我们提供了两个示例项目,一个是用Objective-C编写的,另一个是用Swift编写的。在从仓库中克隆后,要运行Objective-C版本,请在XCode中选择名为AAMultiSelectController-Objc的方案。同样,要运行Swift版本,请选择名为AAMultiSelectController-Swift的方案。

Demo

要求

AAMultiSelectController适用于iOS 8.0及以上,并且需要ARC进行构建。

安装

AAMultiSelectController可通过CocoaPods获得。要安装它,只需将以下行添加到您的Podfile中

pod "AAMultiSelectController"

并编辑Podfile,按照如下命令将AAMultiSelectController安装到项目中

pod install

在Swift项目中使用

使用CocoaPods安装AAMultiSelectController。如果它是一个动态框架,则将@import AAMultiSelectController添加到您的Swift项目的桥接头中。否则,请导入

用法

(请参阅我在示例项目中设置的使用方法)

Objective-C

@property (nonatomic, strong) AAMultiSelectViewController *multiSelectVC;


self.multiSelectVC = [[AAMultiSelectViewController alloc] init];    
self.multiSelectVC.titleText = @"选择语言";
self.multiSelectVC.view.frame = CGRectMake(0, 0,
                                               CGRectGetWidth(self.view.frame) * multiSelectViewWidthRatio,
                                               multiSelectViewHeight);
self.multiSelectVC.itemTitleColor = [UIColor redColor];
self.multiSelectVC.dataArray = [self.dataArray copy];
[self.multiSelectVC setConfirmBlock:^(NSArray *selectedObjects) {
        NSMutableString *message = [NSMutableString stringWithString:@"您选中了:"];
        [selectedObjects enumerateObjectsUsingBlock:^(AAMultiSelectModel * _Nonnull object, NSUInteger idx, BOOL * _Nonnull stop) {
            [message appendFormat:@"%@,", object.title];
        }];
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil
                                                            message:[message copy]
                                                           delegate:nil
                                                  cancelButtonTitle:nil
                                                  otherButtonTitles:@"确定", nil];
        [alertView show];
    }];
self.multiSelectVC.popupShowType = indexPath.row;
self.multiSelectVC.popupDismissType = indexPath.row;
[self.multiSelectVC show];

Swift

    private lazy var multiSelectVC: AAMultiSelectViewController = {
        var vc = AAMultiSelectViewController.init()
        vc.titleText = "Please select a language"
        vc.view.frame = CGRectMake(0, 0,
                                   CGRectGetWidth(self.view.frame) * kMultiSelectViewWidthRatio,
                                   kMultiSelectViewHeight)
        vc.itemTitleColor = UIColor.redColor()
        vc.dataArray = self.dataArray
        vc.confirmBlock = { selectedObjects in
            var message = "You chose:"
            for obj in selectedObjects as! [AAMultiSelectModel] {
                message += "\(obj.title),"
            }
            let alertView: UIAlertView = UIAlertView.init(title: "", message: message, delegate: nil, cancelButtonTitle: "cancel", otherButtonTitles: "confirm")
            alertView.show()
        }
        return vc
    }()

    public func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        tableView.deselectRowAtIndexPath(indexPath, animated: true)
        self.multiSelectVC.popupShowType = AAPopupViewShowType(rawValue: indexPath.row)!
        self.multiSelectVC.popupDismissType = AAPopupViewDismissType(rawValue: indexPath.row)!
        self.multiSelectVC.show()
    }

作者

作者 Gmail Twitter
Alex Ao [email protected] @Alex Ao

许可

AAMultiSelectController可在MIT许可下使用。有关更多信息,请参阅LICENSE文件。