Thursday, September 18, 2014

UIAlertView using Swift in iOS

In this post we create simple UIAlertView using swift programming language in iOS with example.

For create UIAlertView using Swift programming language.
First of all create object of UIAlertView class

var alert: UIAlertView = UIAlertView()
After  that  add title and message to  UIAlertView object.

alert.title =  "Test Alert"
 alert.message = "This is test alert message"
Now add button to alert message like below
alert.addButtonWithTitle("Ok")
Now yout alert dialog is ready. It's time to show your alert dialog.
Show your Alert dialog using show() method.
alert.show()


 
 This is the output of our Alert dialog.
Put below code in method  where you want to show UIAlertView.

            var alert: UIAlertView = UIAlertView()
            alert.title"Test Alert"
            alert.message = "This is test alert message"
            alert.addButtonWithTitle("Ok")
            alert.show() 

That's it...
I hope this post may  helpful to you...

No comments:

Post a Comment