一个简单的,易于定制的 iOS UIAlertView,用 Swift 编写
Malert 用于简化自定义的 alert 视图,如同 UIAlertController
。Malert 允许您个性化 alert 视图,使其符合您的应用布局
要运行示例项目,首先克隆仓库,然后从 Example 目录运行 pod install
要求
- Xcode 10.0+
- Swift 4.0+
版本控制
- Swift 3.x: 1.1.5
- Swift 4.0: 2.0~3.0
- Swift 4.2: 3.1*
- Swift 5: 4.0+
安装
Pod
Malert 通过 CocoaPods 可用。要安装它,只需将以下行添加到 Podfile
pod 'Malert'
手动
如果您不使用任何依赖管理器,可以通过手动集成 Malert 到您的项目中,只需添加包含 Malert 类 的文件。
恭喜!您可以在没有任何依赖管理器的情况下运行 Malert!
示例
这是一个简单的示例。如果您想了解更多信息,请查看应用示例,因为这里有10多个自定义的 Malert。
自定义视图中使用 Malert
import Malert
...
let view = ExampleView.instantiateFromNib()
let malert = Malert(customView: view)
let action = MalertAction(title: "OK")
action.tintColor = UIColor(red:0.15, green:0.64, blue:0.85, alpha:1.0)
malert.addAction(action)
present(malert, animated: true)
如何创建操作
要为您的 malert 添加按钮,有一个名为 addAction
的函数,需要提供一个 MalertAction
对象来构建可自定义的按钮。
let malert = ...
let action = MalertAction(title: "Take the tour") {
print("Closure called when action was clicked")
}
action.cornerRadius = 8
action.tintColor = .white
action.backgroundColor = UIColor(red:0.38, green:0.76, blue:0.15, alpha:1.0)
malert.addAction(action)
...
有关更多详细信息,请参阅示例。
自定义
Malert 提供了一些属性来自定义它
/* Animation attr */
public var presentDuration: TimeInterval
public var dismissDuration: TimeInterval
public var animationType: MalertAnimationType
/* Container attr */
public var margin: CGFloat
public var cornerRadius: CGFloat
public var backgroundColor: UIColor?
/* Title attr */
public var titleFont: UIFont
public var textColor: UIColor
public var textAlign: NSTextAlignment
/* Buttons attr */
public var buttonsHeight: CGFloat
public var separetorColor: UIColor
public var buttonsSpace: CGFloat
public var buttonsSideMargin: CGFloat
public var buttonsBottomMargin: CGFloat
public var buttonsAxis: UILayoutConstraintAxis
做到这一点非常简单。只需在显示之前改变malert的属性强调
let exampleView = ExampleView()
let alert = Malert(customView: exampleView)
//customizing your malert
alert.animationType = .modalRight
alert.buttonsSideMargin = 60
alert.buttonsBottomMargin = 16
alert.buttonsAxis = .horizontal
alert.separetorColor = .clear
自定义操作
Malert 允许一些属性来自定义每个操作
public var tintColor: UIColor
public var backgroundColor: UIColor
public var cornerRadius: CGFloat
public var borderColor: UIColor
public var borderWidth: CGFloat
如果需要更多属性来自定义它,请告诉我们,创建一个问题或一个拉取请求。
贡献
如果你认为我们可以使Malert更强大,请为此项目做出贡献。让我们共同努力,帮助其他开发者。
创建一个拉取请求或者在问题中讨论。非常感谢。
作者
维托·梅什塔,[email protected]
许可
Malert遵循MIT许可,更多信息请查看LICENSE文件。