Skip to content

Instantly share code, notes, and snippets.

@sseno
Created March 29, 2020 00:10
Show Gist options
  • Save sseno/6df13db98108caa6548ad2b320bc49b4 to your computer and use it in GitHub Desktop.
Save sseno/6df13db98108caa6548ad2b320bc49b4 to your computer and use it in GitHub Desktop.
Custom Alert Dialog
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = 3
paragraphStyle.alignment = .left
let titleText = NSAttributedString(
string: "Coming Soon",
attributes: [
NSAttributedString.Key.paragraphStyle: paragraphStyle,
NSAttributedString.Key.foregroundColor : UIColor.black,
NSAttributedString.Key.font : R.font.ubuntuMedium(size: 16)!,
]
)
let messageText = NSAttributedString(
string: "Fitur yang kamu pilih, akan segera kami hadirkan",
attributes: [
NSAttributedString.Key.paragraphStyle: paragraphStyle,
NSAttributedString.Key.foregroundColor : UIColor.black,
NSAttributedString.Key.font : R.font.ubuntu(size: 14)!,
]
)
let alert = UIAlertController(title: "", message: "", preferredStyle: .alert)
alert.setValue(titleText, forKey: "attributedTitle")
alert.setValue(messageText, forKey: "attributedMessage")
alert.view.subviews.first?.subviews.first?.subviews.first?.backgroundColor = .white
if let nav = self.parentContainerViewController()?.navigationController {
nav.present(alert, animated: true) {
alert.view.superview?.isUserInteractionEnabled = true
alert.view.superview?.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.didTapOutsideAlert)))
}
}
@objc func didTapOutsideAlert() {
if let nav = self.parentContainerViewController()?.navigationController {
nav.dismiss(animated: true, completion: nil)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment