WKWebView in Interface Builder

前端 未结 12 867
南旧
南旧 2020-11-30 01:51

It seems that the IB object templates in XCode 6 beta are still creating old-style objects (UIWebView for iOS and WebView for OSX). Hopefully Apple will update them for the

12条回答
  •  半阙折子戏
    2020-11-30 02:32

    Here's a simple Swift 3 version based on crx_au's excellent answer.

    import WebKit
    
    class WKWebView_IBWrapper: WKWebView {
        required convenience init?(coder: NSCoder) {
            let config = WKWebViewConfiguration()
            //config.suppressesIncrementalRendering = true //any custom config you want to add
            self.init(frame: .zero, configuration: config)
            self.translatesAutoresizingMaskIntoConstraints = false
        }
    }
    

    Create a UIView in Interface Builder, assign your constraints, and assign it WKWebView_IBWrapper as a custom class, like so:

    Utilities -> Identity Inspector Tab[1]

提交回复
热议问题