{"id":1290,"date":"2020-12-11T15:35:38","date_gmt":"2020-12-11T07:35:38","guid":{"rendered":"http:\/\/123.57.164.21\/?p=1290"},"modified":"2020-12-11T15:35:38","modified_gmt":"2020-12-11T07:35:38","slug":"ios14-widget%e5%b0%8f%e7%bb%84%e4%bb%b6%e5%bc%80%e5%8f%91%e5%ae%9e%e8%b7%b53-widget%e7%82%b9%e5%87%bb%e4%ba%a4%e4%ba%92","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=1290","title":{"rendered":"iOS14 Widget\u5c0f\u7ec4\u4ef6\u5f00\u53d1\u5b9e\u8df53\u2014\u2014Widget\u70b9\u51fb\u4ea4\u4e92"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2020\/12\/image-10-483x1024.png\" alt=\"\" class=\"wp-image-1291\" width=\"281\" height=\"594\"\/><\/figure><\/div>\n\n\n\n<p>\u524d\u9762\u5b9e\u73b0\u7684<code>Widget<\/code>\u53ea\u662f\u7eaf\u5c55\u793a\u7684\u6837\u5b50\uff0c\u754c\u9762\u642d\u5efa\u4e5f\u53ea\u662f\u7528\u5c55\u793a\u7684<code>Text<\/code>\u5b9e\u73b0\uff0c\u5f53\u70b9\u51fb\u684c\u9762<code>Widget<\/code>\u7684\u65f6\u5019\uff0c\u6253\u5f00\u7684\u662f\u5bf9\u5e94\u7684<code>APP<\/code>\u3002\u5982\u679c<code>Widget<\/code>\u5e03\u5c40\u7684\u65f6\u5019\u7528\u7684\u662f\u6309\u94ae\u3001\u56fe\u7247\u3001\u94fe\u63a5\u7b49\u65b9\u5f0f\uff0c\u60f3\u5b9e\u73b0\u70b9\u51fb\u5bf9\u5e94\u7684\u8df3\u8f6c<code>APP<\/code>\u5bf9\u5e94\u7684\u9875\u9762\u3001\u4e8b\u4ef6\uff0c\u90a3\u4e48\u5c31\u9700\u8981\u989d\u5916\u5904\u7406\u3002<\/p>\n\n\n\n<p>\u6839\u636e\u5b98\u65b9\u6587\u6863\u7684\u63cf\u8ff0\uff0c\u70b9\u51fb<code>Widget<\/code>\u7a97\u53e3\u5524\u8d77<code>APP<\/code>\u8fdb\u884c\u4ea4\u4e92\u6307\u5b9a\u8df3\u8f6c\u652f\u6301\u4e24\u79cd\u65b9\u5f0f\uff1a<\/p>\n\n\n\n<ul><li><strong><code>widgetURL<\/code><\/strong>\uff1a\u70b9\u51fb\u533a\u57df\u662f<code>Widget<\/code>\u7684\u6240\u6709\u533a\u57df\uff0c\u9002\u5408\u5143\u7d20\u3001\u903b\u8f91\u7b80\u5355\u7684\u5c0f\u90e8\u4ef6<\/li><li><strong><code>Link<\/code><\/strong>\uff1a\u901a\u8fc7<code>Link<\/code>\u4fee\u9970\uff0c\u5141\u8bb8\u8ba9\u754c\u9762\u4e0a\u4e0d\u540c\u5143\u7d20\u4ea7\u751f\u70b9\u51fb\u54cd\u5e94<\/li><\/ul>\n\n\n\n<p><code>Widget<\/code>\u652f\u6301\u4e09\u79cd\u663e\u793a\u65b9\u5f0f\uff0c\u5206\u522b\u662f<code>systemSmall<\/code>\u3001 <code>systemMedium<\/code>\u3001<code>systemLarge<\/code>\uff0c\u5176\u4e2d\uff1a<br>1\u3001<code>systemSmall<\/code>\u53ea\u80fd\u7528<code>widgetURL<\/code>\u4fee\u9970\u7b26\u5b9e\u73b0URL\u4f20\u9012\u63a5\u6536\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">@ViewBuilder\nvar body: some View {\n    VStack(content: {\n        Image(\"h_buyao\")\n            .resizable()\n            .frame(width: 50, height: 50)\n            .clipShape(Circle())\n            .overlay(Circle().stroke(Color.white, lineWidth: 4))\n            .shadow(radius: 10)\n        Text(\"\u4e8c\u72d7\u5b50\u4f60\u53d8\u4e86\")\n    })\n    .background(Color.init(red: 144 \/ 255.0, green: 252 \/ 255.0, blue: 231 \/ 255.0))\n    .widgetURL(URL(string: \"https:\/\/www.jianshu.com\/u\/bc4a806f89c5\"))\n}<\/pre>\n\n\n\n<ul><li>2\u3001<code>systemMedium<\/code>\u3001<code>systemLarge<\/code>\u53ef\u4ee5\u7528<code>Link<\/code>\u6216\u8005\u00a0<code>widgetUrl<\/code>\u5904\u7406<\/li><\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">var body: some View {\n    Link(destination: URL(string: \"https:\/\/www.jianshu.com\/u\/bc4a806f89c5\")!) {\n        VStack {\n            Image(\"h_buyao\")\n                .resizable()\n                .frame(width: 50, height: 50)\n                .clipShape(Circle())\n                .overlay(Circle().stroke(Color.white, lineWidth: 4))\n                .shadow(radius: 10)\n            Text(\"\u4e8c\u72d7\u5b50\u4f60\u53d8\u4e86\")\n        }\n    }\n}<\/pre>\n\n\n\n<p><strong>\u8fd9\u4e24\u79cd\u65b9\u5f0f\u7684\u672c\u8d28\u90fd\u662f<code>URL Schemes<\/code><\/strong><br>\u5728\u67e5\u627e\u8d44\u6599\u7684\u65f6\u5019\uff0c\u770b\u5230\u7f51\u4e0a\u6709\u7684\u5730\u65b9\u8bf4\u5728<code>AppDelegate<\/code>\u5b9e\u73b0<code>OpenUrl<\/code>\u8fdb\u884c\u8df3\u8f6c\u5904\u7406\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool<\/pre>\n\n\n\n<p>\u7136\u800c\u8bd5\u4e86\u4e4b\u540e\u53d1\u73b0\u6839\u672c\u6ca1\u6709\u54cd\u5e94\uff0c\u5176\u5b9e\u662f\u9700\u8981\u5728<code>SceneDelegate<\/code>\u91cc\u9762\u5b9e\u73b0\u8df3\u8f6c\u5904\u7406\uff0c\u56e0\u4e3a<code>iOS13<\/code>\u540e\uff0c<code>APP<\/code>\u7684<code>UI<\/code>\u751f\u547d\u5468\u671f\u4ea4\u7531<code>SceneDelegate<\/code>\u7ba1\u7406\uff0c\u8fd9\u91cc\u62ff\u5230\u9700\u8981\u7684<code>URL<\/code>\uff0c\u5c31\u80fd\u5904\u7406\u4ea7\u54c1\u9700\u6c42\u5b9e\u73b0\u4e86\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">func scene(_ scene: UIScene, openURLContexts URLContexts: Set&lt;UIOpenURLContext>) {\n    for context in URLContexts {\n        print(context.url) \/\/ https:\/\/www.jianshu.com\/u\/bc4a806f89c5\n    }\n}<\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u53c2\u8003\u8d44\u6599<\/h4>\n\n\n\n<p><a href=\"https:\/\/links.jianshu.com\/go?to=https%3A%2F%2Fdeveloper.apple.com%2Fdocumentation%2Fwidgetkit%2Fcreating-a-widget-extension\" target=\"_blank\" rel=\"noreferrer noopener\">creating-a-widget-extension<\/a><br><a href=\"https:\/\/links.jianshu.com\/go?to=https%3A%2F%2Fswiftrocks.com%2Fios-14-widget-tutorial-mini-apps\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/swiftrocks.com<\/a><br><a href=\"https:\/\/www.jianshu.com\/p\/1a4d9162daa8\" target=\"_blank\" rel=\"noreferrer noopener\">iOS13 URL Schemes \u8df3\u8f6c\u4e0e\u4f20\u503c\u95ee\u9898<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u9762\u5b9e\u73b0\u7684Widget\u53ea\u662f\u7eaf\u5c55\u793a\u7684\u6837\u5b50\uff0c\u754c\u9762\u642d\u5efa\u4e5f\u53ea\u662f\u7528\u5c55\u793a\u7684Text\u5b9e\u73b0\uff0c\u5f53\u70b9\u51fb\u684c\u9762Widget\u7684\u65f6\u5019\uff0c\u6253\u5f00 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/1290"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1290"}],"version-history":[{"count":1,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/1290\/revisions"}],"predecessor-version":[{"id":1292,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/1290\/revisions\/1292"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1290"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1290"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1290"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}