Last active
January 19, 2019 20:11
-
-
Save shishirthedev/4fb2c8bb23d9ac78bbb83ca4736ce2af to your computer and use it in GitHub Desktop.
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
| func showActionSheet(title:String?, | |
| titleColor: UIColor = UIColor.black, | |
| message: String?, | |
| messageColor: UIColor = UIColor.gray, | |
| backgroundColor: UIColor = UIColor.white){ | |
| guard let message = message else { return } | |
| let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) | |
| // Background color.... | |
| let subview = (alert.view.subviews.first?.subviews.first?.subviews.first!)! as UIView | |
| subview.backgroundColor = backgroundColor | |
| // Border... | |
| subview.layer.borderWidth = 1 | |
| subview.layer.borderColor = UIColor.gray.cgColor | |
| // Corner Radius... | |
| // subview.layer.cornerRadius = 10 | |
| // Title color | |
| if let title = title{ | |
| let attributedTitle = NSAttributedString(string: title, attributes: [ | |
| NSAttributedString.Key.foregroundColor : titleColor | |
| ]) | |
| alert.setValue(attributedTitle, forKey: "attributedTitle") | |
| } | |
| // Message color | |
| let attributedMessage = NSAttributedString(string: message, attributes: [ | |
| NSAttributedString.Key.foregroundColor : messageColor | |
| ]) | |
| alert.setValue(attributedMessage, forKey: "attributedMessage") | |
| // Present and dismiss after 1.5 seconds | |
| self.present(alert, animated: true, completion: nil) | |
| DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1.5){ | |
| alert.dismiss(animated: true, completion: nil) | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment