AlertBar
状态栏上的简单警报。
演示 |
---|
![]() |
用法
导入
import AlertBar
显示警报消息
AlertBar 有默认类型
- 成功
- 错误
- 通知
- 警告
- 信息
AlertBar.show(type: .success, message: "This is a Success message.")
并且您可以自定义 AlertBar 的背景和文本颜色。
选择 custom
类型并设置为 UIColor:.custom(BackgroundColor, TextColor)
AlertBar.show(type: .custom(.lightGray, .black), message: "This is a Custom message.")
警报持续时间
AlertBar 允许自定义警报持续时间。
AlertBar.show(type: .success, message: "This is a Success message.", duration: 10)
AlertBar 选项
AlertBar 接受以下选项:
- 考虑安全区域
- 拉伸条
- 文本对齐方式
使用 setDefault
方法来设置默认选项。
let options = AlertBar.Options(
shouldConsiderSafeArea: true,
isStretchable: true,
textAlignment: .center,
font: UIFont.systemFont(ofSize: 14.0, weight: .medium)
)
AlertBar.setDefault(options: options)
或将 show
方法的参数设置为每个 AlertBar。
let options = AlertBar.Options(
shouldConsiderSafeArea: true,
isStretchable: true,
textAlignment: .center,
font: UIFont.systemFont(ofSize: 14.0, weight: .medium)
)
AlertBar.show(type: .success, message: "This is AlertBar!", options: options)
考虑安全区域
安全区域是从 iOS 11 开始采用的,AlertBar 可以更改是否考虑 SafeArea。
AlertBar.Options#shouldConsiderSafeArea: Bool
默认设置为 true
。
shouldConsiderSafeArea == true |
shouldConsiderSafeArea == false |
---|---|
![]() |
![]() |
拉伸条
如果消息需要多行显示,AlertBar 可以拉伸条状。
AlertBar.Options#isStretchable: Bool
默认设置为 false
。
isStretchable == true |
isStretchable == false |
---|---|
![]() |
![]() |
文本对齐方式
AlertBar 允许自定义文本对齐方式。
安装
CocoaPods
AlertBar 通过 CocoaPods 可用。要安装它,只需将以下行添加到您的 Podfile 中
pod "AlertBar"
Carthage
AlertBar 自版本 0.3.1
开始通过 Carthage 可用。要安装它,只需将以下行添加到您的 Cartfile 中
github "jinSasaki/AlertBar"
作者
candidacy. scrollView. [email protected]
许可证
AlertBar 采用 MIT 许可证。有关更多信息,请参阅 LICENSE 文件。