Message是一个用Swift编写的框架,它使您能够轻松显示信息消息
功能
- 带文本字段和按钮的标准警告
- 带按钮的标准操作表
- 代理
- 下拉消息
用法
简单警告
Alert(withTitle: "Title", message: "Your message").addTextField { textField in
textField.placeholder = "Placeholder"
}
.addButton(withTitle: "Ok")
.addCancelButton(withTitle: "Close")
.show()
简单操作表
ActionSheet(withTitle: "Title", message: "Your message")
.addButton(withTitle: "Ok")
.addCancelButton(withTitle: "Cancel")
.addDestructiveButton(withTitle: "Destructive")
.show()
使用代理
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
Alert(withTitle: "Title", message: "Your message").addTextField { textField in
textField.placeholder = "Placeholder"
}
.addButton(withTitle: "Ok")
.addCancelButton(withTitle: "Close")
.show(withDelegate: self)
}
}
extension ViewController: AlertDelegate {
func willShow(_ alert: AlertProtocol) {
}
func didShow(_ alert: AlertProtocol) {
}
func willDisappear(_ alert: AlertProtocol) {
}
func didDisappear(_ alert: AlertProtocol) {
}
}
高级用法
Alert(withMessage: "Message").addButton(withTitle: "Ok").show(after: 1.0)
Alert(withMessage: "Message").show(andCloseAfter: 2.0)
Alert(withMessage: "Message").show(after: 1.0, andCloseAfter: 2.0)
要求
- iOS 8.0+
- Xcode 8.1, 8.2, 8.3 和 9.0
- Swift 3.0, 3.1, 3.2 和 4.0
沟通
- 如果你发现了错误,请开一个issue。
- 如果你有功能请求,请开一个issue。
- 如果你想贡献,提交一个pull request。
安装
CocoaPods
CocoaPods 是 Cocoa 项目的依赖管理器。你可以使用以下命令安装它
$ gem install cocoapods
要使用 CocoaPods 将 Message 集成到你的 Xcode 项目中,请在你的 Podfile
中指定它
use_frameworks!
target "<Your Target Name>" do
pod "Message"
end
然后,运行以下命令
$ pod install
手动
如果你不希望使用依赖管理器,你可以手动将 Message 集成到你的项目中。
嵌入式框架
-
打开终端,使用
cd
命令进入你的顶级项目目录,如果你的项目还没有作为git仓库初始化,请运行以下命令:$ git init
-
使用以下命令将Message添加为git 子模块:
$ git submodule add https://github.com/incetro/Message.git
-
打开新创建的
Message
文件夹,并将Message.xcodeproj
拖动到Xcode项目导航器中你的应用程序的Xcode项目中。它应该嵌套在应用程序蓝色项目图标下。是否在所有其他Xcode组之上或之下并不重要。
-
在项目导航器中选择
Message.xcodeproj
,并检查部署目标是否与你的应用程序目标匹配。 -
接下来,在项目导航器中选择你的应用程序项目(蓝色项目图标),进入目标配置窗口,并选择侧边栏中的“targets”下的应用程序目标。
-
在该窗口顶部的标签栏上,打开“通用”面板。
-
在“已嵌入的二进制文件”部分下点击
+
按钮。 -
你会看到两个不同的
Message.xcodeproj
文件夹,每个文件夹内都有一个Message.framework
的不同版本,该文件夹位于Products
文件夹内。你可以选择任意一个
Products
文件夹,但必须选择顶部或底部的Message.framework
。 -
对于iOS,选择顶部的
Message.framework
。 -
这样就完成了!
Message.framework
已自动添加为目标依赖项,链接框架和嵌入式框架,在文件复制构建阶段,这样你就可以在模拟器和设备上构建了。
作者
incetro, [email protected]
许可证
Message遵循MIT许可证。更多信息请查看LICENSE文件。