AZDialogViewController
A highly customizable alert dialog controller that mimics Snapchat's alert dialog.
Screenshots
Installation
CocoaPods:
pod 'AZDialogView'
Carthage:
github "Minitour/AZDialogViewController"
Manual:
Simply drag and drop the Sources
folder to your project.
Usage
Create an instance of AZDialogViewController:
let dialog = AZDialogViewController(title: "Antonio Zaitoun", message: "minitour")
Customize:
dialog.titleColor = .black
dialog.messageColor = .black
dialog.alertBackgroundColor = .white
dialog.dismissDirection = .bottom
dialog.dismissWithOutsideTouch = true
dialog.showSeparator = false
dialog.separatorColor = UIColor.blue
dialog.allowDragGesture = false
dialog.rubberEnabled = true
dialog.image = UIImage(named: "icon")
dialog.blurBackground = true
dialog.blurEffectStyle = .dark
dialog.contentOffset = self.view.frame.height / 2.0 - dialog.estimatedHeight / 2.0 - 16.0
Add Actions:
dialog.addAction(AZDialogAction(title: "Edit Name") { (dialog) -> (Void) in
dialog.dismiss()
})
dialog.addAction(AZDialogAction(title: "Remove Friend") { (dialog) -> (Void) in
dialog.dismiss()
})
dialog.addAction(AZDialogAction(title: "Block") { (dialog) -> (Void) in
dialog.dismiss()
})
Add Image:
dialog.imageHandler = { (imageView) in
imageView.image = UIImage(named: "your_image_here")
imageView.contentMode = .scaleAspectFill
return true
}
Custom View
dialog.customViewSizeRatio = 0.2
let container = dialog.container
let indicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)
dialog.container.addSubview(indicator)
indicator.translatesAutoresizingMaskIntoConstraints = false
indicator.centerXAnchor.constraint(equalTo: container.centerXAnchor).isActive = true
indicator.centerYAnchor.constraint(equalTo: container.centerYAnchor).isActive = true
indicator.startAnimating()
Present The dialog:
dialog.show(in: self)
self.present(dialog, animated: false, completion: nil)
Show with completion
dialog.show(in: self) { dialog in
dialog.contentOffset = self.view.frame.height / 2.0 - dialog.estimatedHeight / 2.0 + 15
}
Design
Change Dialog Width
This has been a requested feature and so I decided to add it. You can change the width of the dialog frame as a ratio in respect to the width of the main view. This can only be doing using the initalizer and the width cannot be modified afterwards.
let dialog = AZDialogViewController(title: "Switch Account", message: "My Message", widthRatio: 1.0)
This will display a dialog which has the same width as the the controller it is presented in.
The default value is 0.75
Customize Action Buttons Style:
dialog.buttonStyle = { (button,height,position) in
button.setBackgroundImage(UIImage.imageWithColor(self.primaryColorDark), for: .highlighted)
button.setTitleColor(UIColor.white, for: .highlighted)
button.setTitleColor(self.primaryColor, for: .normal)
button.layer.masksToBounds = true
button.layer.borderColor = self.primaryColor.cgColor
}
Use custom UIButton sub-class:
dialog.buttonInit = { index in
return index == 0 ? HighlightableButton() : nil
}
Customize Tool Buttons:
dialog.rightToolStyle = { (button) in
button.setImage(UIImage(named: "ic_share"), for: [])
button.tintColor = .lightGray
return true
}
dialog.rightToolAction = { (button) in
print("Share function")
}
dialog.leftToolStyle = { (button) in
button.setImage(UIImage(named: "ic_share"), for: [])
button.tintColor = .lightGray
return true
}
dialog.leftToolAction = { (button) in
print("Share function")
}
Customize Cancel Button Style:
dialog.cancelEnabled = true
dialog.cancelButtonStyle = { (button,height) in
button.tintColor = self.primaryColor
button.setTitle("CANCEL", for: [])
return true
}