Closed MattiaConfalonieri closed 6 years ago
Yes sure. You can implement a method in your VC subclass, or create an extension, and add something like that:
func showAlert(_ title: String, message: String, buttonTitle: String, buttonCancel:String, headerImage: UIImage? = nil, completion: @escaping () -> (), cancel: @escaping () -> ()){
let alertController = PMAlertController(title: title, description: message, image: headerImage, style: .alert)
alertController.view.layer.cornerRadius = 6
alertController.alertMaskBackground.backgroundColor = UIColor.black
alertController.alertMaskBackground.alpha = 0.2
alertController.alertTitle.textColor = Colors.Gray.darkestGray
alertController.alertTitle.font = UIFont(name: "HelveticaNeue-Bold", size: 17.0)
alertController.alertDescription.font = UIFont(name: "HelveticaNeue", size: 15.0)
alertController.headerViewHeightConstraint.constant = headerImage != nil ? 100.0 : 0.0
let cancelAction = PMAlertAction(title: buttonCancel, style: .cancel, action: {
cancel()
})
cancelAction.setTitleColor(Colors.Brand.primary, for: .normal)
cancelAction.titleLabel?.font = UIFont(name: "HelveticaNeue-Medium", size: 17.0)
alertController.addAction(cancelAction)
let okAction = PMAlertAction(title: buttonTitle, style: .default, action: {
completion()
})
okAction.setTitleColor(Colors.Brand.primary, for: .normal)
okAction.titleLabel?.font = UIFont(name: "HelveticaNeue-Medium", size: 17.0)
alertController.addAction(okAction)
self.present(alertController, animated: true, completion: nil)
}
Thanks very much, is perfect.
PS : just a correction for future visitors, in your example
alertController.view.layer.cornerRadius = 6
Should be
alertController.alertView.layer.cornerRadius = 12
When I try to override viewDidLoad in a custom class, I get an error that the nib could not be loaded (using Cocoapods).
Please, open a new issue with your problem and show me your code ;)
Thanks -Paolo
Hi, There is a away to customize the alerts once for everyone and not in every single call, Title font, color, action color and font ?