With Xcode 8, this is now possible, but the means to achieve this is a little less hacked. But hey, a working solution is a working solution, right? Let me explain.
WKWebView initWithCoder: no longer annotated as "NS_UNAVAILABLE". Now it looks like below.
- (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
Start by subclassing WKWebView and override initWithCoder. Instead of calling super initWithCoder, you will need to use another init method, such as initWithFrame: configuration :. A quick example below.
- (instancetype)initWithCoder:(NSCoder *)coder { // An initial frame for initialization must be set, but it will be overridden // below by the autolayout constraints set in interface builder. CGRect frame = [[UIScreen mainScreen] bounds]; WKWebViewConfiguration *myConfiguration = [WKWebViewConfiguration new]; // Set any configuration parameters here, eg // myConfiguration.dataDetectorTypes = WKDataDetectorTypeAll; self = [super initWithFrame:frame configuration:myConfiguration]; // Apply constraints from interface builder. self.translatesAutoresizingMaskIntoConstraints = NO; return self; }
In your storyboard, use UIView and give it your own class in your new subclass. The rest is a common thing (setting automatic layout restrictions, binding the view to a socket in the controller, etc.).
Finally, WKWebView scales content differently for UIWebView. Many people will probably want to follow the simple tips in Suppress WKWebView from scaling content for rendering with the same magnification as UIWebView , so that WKWebView closely follows the behavior of UIWebView in this regard.
crx_au Oct 18 '16 at 21:47 2016-10-18 21:47
source share