美文网首页
OC和JS交互 JS注入

OC和JS交互 JS注入

作者: Hamiltonian | 来源:发表于2018-08-16 15:40 被阅读11次
     //网页加载完毕的回调,OCCSwift调用JS
        func webViewDidFinishLoad(_ webView: UIWebView) {
            //调用JS的DOM文档对象
           let title =  self.webview.stringByEvaluatingJavaScript(from: "document.title");
            //调用JS的方法
             self.webview.stringByEvaluatingJavaScript(from: "clickme()");
            print(title ?? "")
        }
        //网页即将加载的回调,JS调用OC Swift
        func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
            var urlString = request.url?.absoluteString
    
      unsigned int count = 0;
        Method *methods = class_copyMethodList([UITextField class], &count);
        for (int i = 0; i < count; i++ ) {
            Method method = methods[i];
           NSString *string =  NSStringFromSelector(method_getName(method));
            NSLog(@"%@",string);
        }
        //修改 : _placeholderLabel
        [self.textfield setValue:[UIColor redColor] forKeyPath:@"placeholderLabel.textColor"];
        //修改 : placeholder
        [self.textfield setValue:@"FUCK" forKey:@"placeholder"];
    
    
    

    相关文章

      网友评论

          本文标题:OC和JS交互 JS注入

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