MMActionSheet 是一个简单的弹出选择框,使用纯swift编写,类似于微信的actionsheet
MMActionSheet is an simple pop-up selection box(ActionSheet) written in pure Swift. Similar to the wechat actionsheet
- iOS 8.0+
- swift 4.0+
To install with Swift Package Manager, add this package to your project’s 'Swift Packages' section. Or add the following line to your Package.swift:
.package(url: "https://github.com/MinMao-Hub/MMActionSheet.git", from: "2.0.0")
-
To install MMActionSheet using CocoaPods, integrate it in your existing Podfile, or create a new Podfile:
platform :ios, '8.0' use_frameworks! target 'MyApp' do pod 'MMActionSheet', '~> 2.0' end
-
Execute command:
pod repo update master
pod install
-
Import MMActionSheet in you code
import MMActionSheet
Just clone and add components dir to your project.
let buttons = [
MMButtonItem(title: "拍照", titleColor: .default, buttonType: .default(index: 0)),
MMButtonItem(title: "相册", titleColor: .default, buttonType: .default(index: 1)),
]
let titleItem = MMTitleItem(title: "请选择照片", titleColor: .red)
let cancelButton = MMButtonItem(title: "取消", titleColor: .default, buttonType: .cancel)
let mmActionSheet = MMActionSheet(title: titleItem, buttons: buttons, duration: nil, cancelButton: cancelButton)
mmActionSheet.selectionClosure = { item in
if let currentItem = item, let type = currentItem.buttonType {
switch type {
case let .default(index):
print("== default index \(index) ==")
case .cancel:
print("cancel")
}
}
}
mmActionSheet.present()
PS:注释
- create actionsheet && init 【创建并初始化】
MMActionSheet(title: titleItem, buttons: buttons, duration: nil, cancelButton: cancelButton)
-
argument【参数描述】
-
title
头部标题,类型为MMTitleItem
-
buttons
事件按钮数组,类型为Array<MMButtonItem>
,里面包含每一个按钮的具体属性:public var title: String? public var titleColor: MMButtonTitleColor? = .default public var titleFont: UIFont? = .systemFont(ofSize: 16.0) public var buttonType: MMButtonType? public var backgroudImageColorNormal: MMButtonTitleColor? = .custom(MMTools.DefaultColor.normalColor) public var backgroudImageColorHighlight: MMButtonTitleColor? = .custom(MMTools.DefaultColor.highlightColor)
title
按钮标题titleColor
按钮颜色titleFont
按钮字体type
按钮类型(展示不同的标题颜色)【枚举类型 -default
,blue
,danger
,custom
】backgroudImageColorNormal
正常背景色backgroudImageColorHighlight
选中背景色
-
duration
动画时长 -
cancelBtn
取消按钮属性,属性跟上述buttons内部button属性一致;若设置为nil
则不显示该按钮
-
-
callback【回调】
mmActionSheet.selectionClosure = { item in
if let currentItem = item, let type = currentItem.buttonType {
switch type {
case let .default(index):
print("== default index \(index) ==")
case .cancel:
print("cancel")
}
}
}
item
该handler即为buttons里面的MMButtonItem
,对应的回调过来
- present【弹出actionsheet】
mmActionSheet.present()
You are welcome to fork and submit pull requests.
MMActionSheet is open-sourced software licensed under the MIT license.