Skip to content

Instantly share code, notes, and snippets.

@shishirthedev
Last active January 19, 2019 20:11
Show Gist options
  • Select an option

  • Save shishirthedev/4fb2c8bb23d9ac78bbb83ca4736ce2af to your computer and use it in GitHub Desktop.

Select an option

Save shishirthedev/4fb2c8bb23d9ac78bbb83ca4736ce2af to your computer and use it in GitHub Desktop.
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