Ankit Kr.Vishwakarma Ankit Kr.Vishwakarma - 1 month ago 12x
iOS Question

How can i present uiview (xib) as alert view in swift

I want to present the my xib as the alert view.
In the xib main view is going to be semi-transparent, which will prevent users from tapping on anything else in the background while the alert view is up. I am not using the view controller in xib.


// 1. Declare view like this way in side the showAlert Methods

let alert = NSBundle.mainBundle().loadNibNamed("Alert", owner: self, options: nil).last as! UIView     

// 2. compose methods like this way

static func showAlert() {
        let windows = UIApplication.sharedApplication().windows
        let lastWindow = windows.last
        alert.frame = UIScreen.mainScreen().bounds

    static func removeAlert() {

// 3. call when ever you want to show it.

    //showing alert

    //remove alert