dillidon/alerts-and-pickers

webview in alert

dalekzhangdong opened this issue · 3 comments

I want add a vebview in alert,
let title = "Privacy Policy"
let message = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)

        let subview = alert.view.subviews.first
        let bgview = subview?.subviews.first
        bgview?.backgroundColor = UIColor(red: 255, green: 255, blue: 255)
        bgview?.layer.cornerRadius = 10
        print(alert.view.frame.size.width)

        alert.addAction(UIAlertAction(title: "Yes", style: .default, handler: nil))
        alert.addAction(UIAlertAction(title: "No", style: .cancel, handler: nil))
        
        
        
        let web = UIWebView(frame: CGRect(x: 0, y: 50, width: alert.view.bounds.size.width * 0.7, height: self.view.frame.size.height * 0.70 - 95))

        let requestURL = NSURL(string: "http://google.com");
        let request = NSURLRequest(url: requestURL! as URL);
        web.loadRequest(request as URLRequest);
        
        web.scalesPageToFit = true
        web.loadRequest(request as URLRequest)
        alert.view.addSubview(web)
        
        self.present(alert, animated: true)

but I can't set the webview width

@dalekzhangdong instead of alert.view.addSubview(web) use alert.setValue(vc, forKey: "contentViewController")

Not working

instead of alert.view.addSubview(web) use alert.setValue(vc, forKey: "contentViewController")