swift UIWebView进入警报

时间:2015-06-18 18:33:16

标签: swift uiwebview uialertview

我想以编程方式在UIWebView中打开警报。所以我创建了一条消息,一个动作,我将自己的大小设置为UIAlert。

以下是我的代码:

before

好的,我的结果是这样的 enter image description here

我真的不喜欢那个按钮在WebView上的位置,它应该在视图之下。

提前致谢。

1 个答案:

答案 0 :(得分:-1)

您应该向\n\n\n\n\n\n\n\n\n\n\n\n添加另一组var message = "\n\n\n\n\n\n\n\n\n\n\n\n";,使其变为var message = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n”;。 UIWebView似乎不会影响UIAlertController的高度,它看起来像是消息。这应该可以解决问题,但您应该考虑将所有var更改为let

以下是完整代码的外观:     让title ="隐私政策"     让消息=" \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n ñ\ n \ n&#34 ;;

let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
let cancel = UIAlertAction(title: "Chiudi", style: UIAlertActionStyle.Destructive, handler: nil)

let height:NSLayoutConstraint = NSLayoutConstraint(item: alert.view, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: self.view.frame.height * 0.90)
alert.view.addConstraint(height);
alert.view.frame.size.height = self.view.frame.height * 0.90

let web = UIWebView(frame: CGRect(x: 15, y: 50, width: self.view.frame.size.width * 0.8 - 15, height: self.view.frame.size.height * 0.85 - 95)) // take note that right here, in the height:, I’ve changed 0.8 to 0.85 so it should look more consistent on the top and bottom
let requestURL = NSURL(string: "http://www.google.it");
let request = NSURLRequest(URL: requestURL!);
web.loadRequest(request);

web.scalesPageToFit = true
web.loadRequest(request)
alert.view.addSubview(web)
alert.addAction(cancel)
self.presentViewController(alert, animated: true, completion: nil)

应该只需要它:)