Why isn't my WKWebView resizing inside my subplot?

I am creating a minimal WebKit browser for Mac OS App using the following Swift code to load a new WKWebView into a custom view object.

When I run the application, the webpage loads correctly and fills the window, however if the window is resized, the subview does not resize with the window.

Any help would be greatly appreciated.

import Cocoa 
import WebKit
import AppKit

@NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate {

@IBOutlet weak var window: NSWindow!

@IBOutlet weak var customView: NSView!

func applicationDidFinishLaunching(aNotification: NSNotification) {
    // Insert code here to initialize your application
    var url = NSURL(string:"http://www.google.com/")
    var request = NSURLRequest(URL:url!)
    var theWebView:WKWebView = WKWebView(frame: customView.bounds)
    self.customView.autoresizingMask = NSAutoresizingMaskOptions.ViewWidthSizable | NSAutoresizingMaskOptions.ViewHeightSizable
    self.customView.addSubview(theWebView)
    theWebView.loadRequest(request)
}

func applicationWillTerminate(aNotification: NSNotification) {
    // Insert code here to tear down your application
}
}

      

+3


source to share





All Articles