CustomAlertController for iOS
CustomAlertController 是显示自定义提示框的简单方法。库受 UIAlertController 启发,我们试图以相同的方式实现相同的功能并采用相同的样式。
屏幕截图
基本示例
// basic usage
let vc = BeAlertController(title: "title", message: "message")
vc.addAction(action: BeAlertAction(title: "Ok", style: .default, handler: { (action) in
}) )
vc.addAction(action: BeAlertAction(title: "Cancel", style: .destructive, handler: { (action) in
}))
present(vc, animated: true, completion: nil)
但是等等,还有更多!
您可以更新以下属性并自定义
lazy public var backgroundColor = UIColor(hex: "949494")
lazy public var backgroundAlpha: CGFloat = 0.75
lazy public var contentBackgroundColor = UIColor(hex: "ebebeb")
lazy public var contentBackgroundCornerRadius: CGFloat = 10
lazy public var titleTextColor: UIColor = UIColor(hex: "211c45")
lazy public var titleTextFont: UIFont = UIFont.boldSystemFont(ofSize: 15)
lazy public var spacingAfterTitle: CGFloat = 10
lazy public var messageTextColor: UIColor = UIColor(hex: "211c45")
lazy public var messageTextFont: UIFont = UIFont.systemFont(ofSize: 14)
lazy public var spacingAfterMessage: CGFloat = 10
lazy public var defaultButtonTextColor: UIColor = UIColor(hex: "ffffff")
lazy public var defaultButtonBackgroundColor: UIColor = UIColor(hex: "f92f57")
lazy public var defaultButtonCornerRadius: CGFloat = 5
lazy public var defaultButtonFont: UIFont = UIFont.systemFont(ofSize: 14)
lazy public var spacingAfterDefaultButton: CGFloat = 10
lazy public var destructiveButtonTextColor: UIColor = UIColor(hex: "757575")
lazy public var destructiveButtonBackgroundColor: UIColor = UIColor(hex: "cccccc")
lazy public var destructiveButtonCornerRadius: CGFloat = 5
lazy public var destructiveButtonFont: UIFont = UIFont.systemFont(ofSize: 14)
您还可以创建一个子类并在您的应用程序中全局使用它,下面是一个示例
class GlobalAlertController: BeAlertController{
override init(title: String?, message: String?) {
super.init(title: title, message: message)
//Do your customizations here
defaultButtonBackgroundColor = .blue
defaultButtonTextColor = .white
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}
//Usage
let vc = GlobalAlertController(title: "Custom Alert Controller", message: "Thank you for using custom alert controller, Hopefully you found it a smart help.\nDo let us know if you need any other feature.")
vc.addAction(BeAlertAction(title: "Got it", style: .default, handler: { (action) in
}))
vc.addAction(BeAlertAction(title: "Cancel", style: .destructive, handler: { (action) in
}))
present(vc, animated: true, completion: nil)
设置说明
CocoaPods
使用 CocoaPods 安装,请在您的 Podfile
文件中添加以下内容
pod 'CustomAlertController'
手动安装
- 将
BeAlertController.swift
文件添加到您的项目中。 - 给自己来杯冷饮
🍺 .
MIT 许可协议
Copyright (c) 2019 Shahbaz Saleem.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.