首页 » Swift » MMActionSheet介绍(自定义的UIActionSheet弹出框组件)

MMActionSheet介绍(自定义的UIActionSheet弹出框组件)

原文 http://blog.csdn.net/u012988591/article/details/78210073

2017-10-15 12:20:19阅读(547)

MMActionSheet Introduction

MMActionSheet 是一个简单的弹出选择框,使用纯swift编写,类似于微信的actionsheet

MMActionSheet is an simple pop-up selection box(ActionSheet) written in pure Swift. Similar to the wechat actionsheet

Rquirements iOS 8.0+ Xcode 9 (swift 4)
current code keep on swift4 Xcode 8 (swift 3)
If you want to run demo in swift3, please switch branch to swift3.0 Installation ① Cocoapods pod 'MMActionSheet', '~> 0.0.5' import MMActionSheet in you code ② Copy code into project

克隆代码,然后将components文件夹下面的两个文件 MMActionSheet.swift 和 MMButton.swift加入到你的项目中即可。

Just clone and add MMActionSheet.swift, MMButton.swift to your project.

Example

1、 has “Cancel” buttons and titles【有标题有取消按钮】

MMActionSheet介绍(自定义的<a href=UIActionSheet弹出框组件)" src="http://img.blog.csdn.net/20171015112553114?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMjk4ODU5MQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="有标题有取消按钮" title="">

2、 has a “Cancel” button but no title【无标题有取消按钮(类似于微信)】

MMActionSheet介绍(自定义的UIActionSheet弹出框组件)

3、 no “Cancel” button and no title【无标题无取消按钮】

MMActionSheet介绍(自定义的UIActionSheet弹出框组件)

4、 has a title but no “Cancel” button【有标题无取消按钮】

MMActionSheet介绍(自定义的UIActionSheet弹出框组件)

5、 Defines the title color【定义标题颜色】
目前仅支持三种(default,blue,danger)

MMActionSheet介绍(自定义的UIActionSheet弹出框组件)

Usage
let buttons = [
    [
        "title": "拍照",
        "handler": "camera",
    ],[
        "title": "相册",
        "handler": "photos",
        "type": "default"
    ]
] 
let mmActionSheet = MMActionSheet.init(title: "请选择照片", buttons: buttons, duration: nil, cancel: true)
mmActionSheet.callBack = { (handler) ->() in
    print(handler)
}
mmActionSheet.present()

PS:注释

create actionsheet && init 【创建并初始化】

MMActionSheet.init(title: "请选择照片", buttons: buttons, duration: nil, cancel: true)

argument【参数描述】

title 头部标题

buttons 事件按钮数组,类型为Array<Dictionary<String, String>>,里面包含每一个按钮的具体属性:

[
    "title": "拍照",
    "handler": "camera",
    "type": "default"
]
title 按钮标题 handler 按钮事件唯一标识,回调的时候根据该值区别处理事件 type 按钮类型(展示不同的标题颜色)【default,blue,danger】 duration 动画时长 cancel 是否需要取消按钮 callback【回调】
mmActionSheet.callBack = { (handler) ->() in
    print(handler)
}

handler 该handler即为buttons里面button的handler,对应的回调过来

present【弹出actionsheet】

mmActionSheet.present()

Contacts

Github–https://github.com/MinMao-Hub
Email:1286090267@qq.com

最新发布

CentOS专题

关于本站

5ibc.net旗下博客站精品博文小部分原创、大部分从互联网收集整理。尊重作者版权、传播精品博文,让更多编程爱好者知晓!

小提示

按 Ctrl+D 键,
把本文加入收藏夹