Displaying Simple Toast in IOS Swift
1 min readJul 10, 2018
Hi i want to share how to display a toast message in IOS like android.
create a function with parameters like controller, message and duration.
func showToast(controller: UIViewController, message : String, seconds: Double)
creating a alert using alert controller because ios doesn't have toast functionality like android inbuilt.
let alert = UIAlertController(title: nil, message: message, preferredStyle: .alert)
creating a background color, alpha value, corner radius if necessary to look transparent
alert.view.backgroundColor = .black
alert.view.alpha = 0.5
alert.view.layer.cornerRadius = 15
Displaying the UIAlertController.
controller.present(alert, animated: true)
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + seconds) {
Dismissing the alert
alert.dismiss(animated: true)
calling function where its needed to display alert
example: