添加WkWebView约束

时间:2018-04-06 20:37:01

标签: ios swift wkwebview

我在笔尖中添加了一个wkwebView。我无法将大小从wkWebView设置为contentView(BlueView)。 BlueView的约束是正确的。这是我的代码:

感谢您的帮助

@IBOutlet weak var view: UIView!
@IBOutlet weak var contentView: UIView!
@IBOutlet weak var stopButton: UIButton!
@IBOutlet weak var skipButton: UIButton!
@IBOutlet weak var infoLabel: UILabel!

var webView = WKWebView(frame: .zero)

override func awakeFromNib() {

    webView.frame.size = CGSize(width: contentView.bounds.width, height: contentView.bounds.height)
    contentView.addSubview(webView)

    let myURL = URL(string: "https://www.apple.com")
    let myRequest = URLRequest(url: myURL!)
    webView.load(myRequest)

}

override init(frame: CGRect) {
    super.init(frame: frame)
    xibSetup()
}

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    xibSetup()

}

func xibSetup() {
    view = loadViewFromNib()

    // use bounds not frame or it'll be offset
    view.frame = bounds

    // Make the view stretch with containing view
    view.autoresizingMask = [UIViewAutoresizing.flexibleWidth, UIViewAutoresizing.flexibleHeight]

    // Adding custom subview on top of our view (over any custom drawing > see note below)
    addSubview(view)

}
 func loadViewFromNib() -> UIView! {

    let bundle = Bundle(for: type(of: self))
    let nib = UINib(nibName: "ReCaptchaV2", bundle: bundle)
    let view = nib.instantiate(withOwner: self, options: nil).first as! UIView

    return view
}

enter image description here

enter image description here

2 个答案:

答案 0 :(得分:2)

设置这些约束

select user_id,
   min(date) as started, 
   max(date) as ended,
   datediff(day, 
            min(date),
            max(date)) as duration
from myTable
where event in ('started', 'ended')
group by user_id

答案 1 :(得分:0)

父视图设置约束,而不是从安全区域设置约束。并且只保留4个约束。所以:

  

父视图中的尾随约束= 0
  按钮的底部约束= 0
  来自父视图的顶部约束= 0
  父视图中的左约束= 0

检查这些屏幕截图:

<强> 1。约束:

enter image description here

<强> 2。在约束中选择的父视图:

enter image description here

第3。输出:

enter image description here