Created
March 29, 2020 00:10
-
-
Save sseno/6df13db98108caa6548ad2b320bc49b4 to your computer and use it in GitHub Desktop.
Custom Alert Dialog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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