类别 | 详情说明 |
方法功能 | 显示界面 |
方法签名 | Void show() |
返回值 | Void |
参数 | 无 |
案例 | var web = new WebView() web.show(); web.loadHtml(` <!DOCTYPE html> <html lang="en"> < head > < meta charset = "UTF-8" > < title > WKWebView JS to Swift </ title > < style > body { font - family: -apple - system, BlinkMacSystemFont, sans - serif; padding: 40px; background - color: #f2f2f7; text - align: center; } button { font-size: 18px; padding: 12px 24px; margin: 10px; border: none; border-radius: 8px; background-color: #007aff; color: white; cursor: pointer; } button: hover { background - color: #005fd1; } </ style > </ head > < body > < h1 > Swift 调用演示 </ h1 > < button > 设置值 </ button > < button > 加载脚本 </ button > < script > async function main() { //写入配置参数 setConfig('a', '6666') //获取配置参数 const result = await getConfig("a"); //吐司提示 toast(result.toString()) //运行脚本代码,脚本要写到lamada表达式里 runJS(() => { //脚本写这里 printl("1233") }) //运行脚本文件 runFile("主脚本.js") } </ script > </ body > </ html > `) |
类别 | 详情说明 |
方法功能 | 加载本地文件 |
方法签名 | Void loadFile(String path) |
返回值 | Void |
参数 | - String path :文件路径 |
案例 | var fileLoader = new FileLoader(); fileLoader.loadFile("/sdcard/test.txt"); // 加载指定路径的本地文件 |
类别 | 详情说明 |
方法功能 | 加载 HTML 内容 |
方法签名 | Void loadHtml(String html) |
返回值 | Void |
参数 | - String html :HTML 字符串 |
案例 | var webView = new WebView(); webView.loadHtml("<h1>Hello</h1>"); // 加载 HTML 内容 |
类别 | 详情说明 |
方法功能 | 关闭界面 |
方法签名 | Void dismiss() |
返回值 | Void |
参数 | 无 |
案例 | var window = new Window(); window.dismiss(); // 关闭该界面 |
类别 | 详情说明 |
方法功能 | 加载网页 URL |
方法签名 | Void loadUrl(String url) |
返回值 | Void |
参数 | - String url :网址字符串 |
案例 | var webView = new WebView(); webView.loadUrl("https://www.example.com"); // 加载指定网址的网页 |
欢迎光临 B2B网络软件 (http://bbs.niubt.cn/) | Powered by Discuz! X3.2 |