美文网首页
xib使用WKWebView

xib使用WKWebView

作者: MoMo鲸 | 来源:发表于2017-02-27 16:56 被阅读644次

    我在 Xcode 的 IB 中没找见WKWebView控件,只有 UIWebView 控件。

    我新建了一个 UIView ,并将其自定义类设置为WKWebView,结果允许时,直接闪退了。

    原因是因为WKWebView并没有实现这个方法

    - (instancetype)initWithCoder:(NSCoder *)coder NS_UNAVAILABLE;
    

    经过检查,发现目前只能使用代码方式来创建WKWebView。

    后来想到一个方法 就是写一个类继承自WKWebView。在.m文件中重写initWithCoder方法。

    - (instancetype)initWithCoder:(NSCoder *)coder{
    
        CGRect frame = [[UIScreen mainScreen] bounds];
        WKWebViewConfiguration *myConfiguration = [WKWebViewConfiguration new];
       
        self = [super initWithFrame:frame configuration:myConfiguration];
        
        self.translatesAutoresizingMaskIntoConstraints = NO;
        
        return self;
    }
    

    然后在xib中使用UIView,并将其自定义类设置为myWK即可使用。

    相关文章

      网友评论

          本文标题:xib使用WKWebView

          本文链接:https://www.haomeiwen.com/subject/qmgzwttx.html