MatinAlertFramework
MatinAlertFramework 是一个开源库,可以轻松地为 iOS 创建可定制的 可滚动 提示弹出窗口。
自定义样式
视频示例https://player.vimeo.com/video/506645136
要求
- 需要 iOS 13 或更高版本。
许可证
请参阅许可证。您可以在个人或商业项目中自由修改和使用此库。无需署名,但我们非常欢迎。一点“谢谢!”(或类似的话语)总是受欢迎的!
安装
Swift包管理器
将https://github.com/matin-kaj/MatinAlertFramework
添加为您的Package.swift
文件的依赖项,或在Xcode中选择文件 -> Swift包 -> 添加包依赖项...
。
CocoaPods
使用CocoaPods安装MatinAlertFramework是最简单的方式。只需在您的Podfile中添加以下行:
pod 'MatinAlertFramework'
用法
import MatinAlertFramework
简单警告
# displays the content with an OK button
MatinAlert().display(withContent: "Please make sure to do something!")
带有标题的警告消息
# displays the content with an OK button with a blue header along with a title.
MatinAlert().display("Notice", contentText: "Please make sure to do something!")
带标题和警告警报类型的警告消息
# displays the content with an OK button and with orange warning header along with a title.
MatinAlert().display("Warning", contentText: "Please make sure to do something!", alertType: .warning)
带标题和警告警报类型及第一个按钮标题的警告消息
# displays the content with an Okay button title with an orange warning header along with a title.
MatinAlert().display("Warning", contentText: "Please make sure to do something!", alertType: .warning, firstButtonTitle: "Okay")
带标题和警告警报类型及第一个和第二个按钮标题的警告消息
# displays the content with `Yes` and `No` as a title of first and second buttons with an orange warning header along with a title.
MatinAlert().display(
"Warning",
contentText: "Are you sure you want to do something!",
alertType: .warning,
firstButtonTitle: "Yes",
secondButtonTitle: "No")
带标题和警告警报类型及第一个和第二个按钮标题和按钮点击关闭的警告消息
# displays the content with `Yes` and `No` as a title of first and second buttons with an orange warning header along with a title.
# and receive on tap button's event
MatinAlert().display(
"Warning",
contentText: "Are you sure you want to do something!",
alertType: .warning,
firstButtonTitle: "Yes",
secondButtonTitle: "No") { (tappedButton) in
// callback when button is tapped.
switch(tappedButton) {
case .confirm:
// the first button clicked
MatinAlert().display(withContent: "You rock!")
case .cancel:
// the second button clicked
MatinAlert().display(withContent: "You still rock!")
}
}
具有自定义样式的警告消息
# configures custom styles and displays the content
var customStyle = MatinAlert.CustomStyle()
var topHeaderViewStyle = MatinAlert.CustomViewStyle()
var topHeaderTextStyle = MatinAlert.CustomTextStyle()
var buttonStyle = MatinAlert.CustomButtonStyle()
let buttonFont = UIFont(name: "Menlo-Bold", size: 16)
# set custom style for top header view
topHeaderViewStyle.color = UIColor.systemIndigo
topHeaderViewStyle.borderColor = UIColor.systemGray
customStyle.topHeaderView = topHeaderViewStyle
# set custom style for top header title
topHeaderTextStyle.color = UIColor.white
topHeaderTextStyle.alignment = .left
customStyle.topHeaderText = topHeaderTextStyle
# set custom styles for the first button
buttonStyle.bgColor = UIColor.systemRed
buttonStyle.font = buttonFont
buttonStyle.titleColor = UIColor.white
customStyle.firstButton = buttonStyle
# set custom styles for the second button
buttonStyle.titleColor = UIColor.white
buttonStyle.bgColor = UIColor.systemTeal
buttonStyle.font = buttonFont
customStyle.secondButton = buttonStyle
MatinAlert().display(
"Custom Styles",
contentText: "You are seeing customized alert message. Do you like it?",
alertType: .custom(style: customStyle),
firstButtonTitle: "Yes",
secondButtonTitle: "No")
具有持久样式的警告消息
# configures custom styles and sets it as a default style. The alert will use this style throughout the app
var customStyle = MatinAlert.CustomStyle()
var topHeaderViewStyle = MatinAlert.CustomViewStyle()
var topHeaderTextStyle = MatinAlert.CustomTextStyle()
var buttonStyle = MatinAlert.CustomButtonStyle()
let buttonFont = UIFont(name: "Menlo-Bold", size: 16)
# set custom style for top header view
topHeaderViewStyle.color = UIColor.systemIndigo
topHeaderViewStyle.borderColor = UIColor.systemGray
customStyle.topHeaderView = topHeaderViewStyle
# set custom style for top header title
topHeaderTextStyle.color = UIColor.white
topHeaderTextStyle.alignment = .left
customStyle.topHeaderText = topHeaderTextStyle
# set custom styles for the first button
buttonStyle.bgColor = UIColor.systemRed
buttonStyle.font = buttonFont
buttonStyle.titleColor = UIColor.white
customStyle.firstButton = buttonStyle
# set custom styles for the second button
buttonStyle.titleColor = UIColor.white
buttonStyle.bgColor = UIColor.systemTeal
buttonStyle.font = buttonFont
customStyle.secondButton = buttonStyle
# you can configure your custom style once then alert will always use the same style
MatinAlert.setDefaultStyle(customStyle: customStyle)
MatinAlert().display("predefined Styles", contentText: "You are seeing a predefined alert message.", alertType: .predefined)
贡献
欢迎拉取请求。对于重大更改,请首先创建一个问题来讨论您想要进行的更改。