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
通信
- 如果你 发现了错误,请开启一个问题。
- 如果你 有功能请求,请开启一个问题。
- 如果你 希望贡献,提交一个拉取请求。
安装
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
-
通过运行以下命令将“消息”作为 git 子模块添加
$ git submodule add https://github.com/incetro/Message.git
-
打开新的
Message
文件夹,并将Message.xcodeproj
拖动到你的应用程序 Xcode 项目的“项目导航器”中。它应该嵌套在你应用程序的蓝色项目图标下方。它在所有其他 Xcode 组之上或之下并不重要。
-
在项目导航器中选中
Message.xcodeproj
,并验证部署目标与你的应用程序目标相匹配。 -
接下来,在项目导航器(蓝色项目图标)中选中你的应用程序项目,导航到目标配置窗口,并在侧边栏的“目标”下选中应用程序目标。
-
在该窗口顶部的标签栏中,打开“通用”面板。
-
在“已嵌套二进制”部分下点击
+
按钮。 -
你会看到两个不同的
Message.xcodeproj
文件夹,每个文件夹内部都有一个嵌套在“Products”文件夹中的两个不同版本的Message.framework
。你选择哪个“Products”文件夹不重要,但是选择顶部或底部的
Message.framework
很重要。 -
为 iOS 选择顶部的
Message.framework
。 -
就这样!
Message.framework
将自动添加为目标依赖项,链接框架并在复制文件构建阶段嵌入框架,这对在模拟器和设备上构建来说是所有你需要的。
作者
incetro, [email protected]
许可协议
Message 在 MIT 许可协议下可用。有关更多信息,请参阅 LICENSE 文件。