{"id":314,"date":"2020-08-04T23:10:02","date_gmt":"2020-08-04T15:10:02","guid":{"rendered":"http:\/\/123.57.164.21\/?p=314"},"modified":"2020-08-05T12:17:20","modified_gmt":"2020-08-05T04:17:20","slug":"swiftui-%e5%b8%83%e5%b1%80%e7%b3%bb%e7%bb%9f","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=314","title":{"rendered":"SwiftUI \u5e03\u5c40\u7cfb\u7edf"},"content":{"rendered":"\n<p><strong>SwiftUI \u4f7f\u7528\u7075\u6d3b\u7684\u76d2\u5b50\u5e03\u5c40\u7cfb\u7edf\uff0cSwiftUI \u7684\u5e03\u5c40\u4e3b\u8981\u6b65\u9aa4\u5982\u4e0b:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">1. \u7236 View \u4e3a\u5b50 View \u5efa\u8bae\u4e00\u4e2a\u5927\u5c0f\u3002\n2. \u6839\u636e\u5efa\u8bae\u5927\u5c0f\uff0c \u5b50View \u786e\u5b9a\u81ea\u5df1\u7684\u5927\u5c0f\u3002\n3. \u7236 View\u5c06\u5b50View \u653e\u5728\u9002\u5f53\u7684\u4f4d\u7f6e\u3002<\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p><strong>\u6848\u4f8b1<\/strong><\/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=\"\">\/\/ \u6848\u5217\u4ee3\u78011\nstruct ContentView: View {\n      var body: some View {\n      Text(\"Hello, SwiftUI!\") .background(Color.orange)\n }\n }<\/pre>\n\n\n\n<p>\u6b64\u65f6\u663e\u793a\u7684\u5185\u5bb9\u4e3a\u6a58\u8272\u80cc\u666f\u56f4\u7ed5\u7740\u6587\u672c<strong>&#8220;Hello, SwiftUI!&#8221;<\/strong>\uff0c\u5b83\u53ea\u7528\u4e86\u4e00\u4e2a \u201c\u8db3\u591f\u7684\u7a7a\u95f4\u201d \u6765\u9002\u5e94\u663e\u793a\u7684\u5185\u5bb9\u3002\u90a3\u4e48\u73b0\u5728\u7684\u95ee\u9898\u662f:ContentView \u5230\u5e95\u6709\u591a\u5927? \u5176\u5b9e ContentView \u7684\u5927\u5c0f\u662fbody \u91cc\u9762\u6240\u5448\u73b0\u7684\u5185\u5bb9\u7684\u5927\u5c0f\uff0c\u4e5f\u5c31\u662f\u8bf4 ContentView \u6ca1\u6709\u81ea\u5df1\u7684\u5927\u5c0f\uff0c\u800c\u662f\u8c03\u6574\u81ea\u5df1\u7684\u5927\u5c0f\u4ee5\u9002\u5e94\u5185\u5bb9\u9700\u8981\u7684\u5927\u5c0f\uff0c\u8fd9\u5c31\u662f SwiftUI \u4e2d\u6240\u8c13\u7684\u5e03\u5c40\u65e0\u5173( layout neutral )\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p><strong>\u5e03\u5c40\u65e0\u5173<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\u2022 \u5982\u679c\u4e00\u4e2a View \u5e03\u5c40\u65e0\u5173\uff0c\u5219\u53ef\u4ee5\u7ed8\u5236\u4efb\u4f55\u5927\u5c0f\u7684 View\u3002\n\u2022 \u5e03\u5c40\u65e0\u5173\u7684 View \u4f1a\u901a\u8fc7\u8be2\u95ee\u5176\u5b50 View \u9700\u8981\u591a\u5c11\u7a7a\u95f4\u5e76\u4f7f\u7528\u76f8\u540c\u7684\u503c\u6765\u786e\u5b9a\u6240\u9700\u7684\u7a7a\u95f4\u3002\n\u2022 \u5982\u679c View \u7684\u5c42\u6b21\u7ed3\u6784\u662f\u5b8c\u5168\u5e03\u5c40\u65e0\u5173\u7684\uff0c\u90a3\u4e48\u5b83\u5c06\u81ea\u52a8\u5360\u7528\u6240\u6709\u53ef\u7528\u7684\u7a7a\u95f4\u3002 \u4f8b\u5982\uff0c\n\u5f62\u72b6\u548c\u989c\u8272\u7684\u5e03\u5c40\u662f\u4e2d\u7acb\u7684\uff0c\u5982\u679c View \u4ec5\u5305\u542b\u4e00\u4e2a\u989c\u8272\u6216\u4e00\u79cd\u5f62\u72b6\uff0c\u90a3\u4e48\u5b83\u4f1a\u81ea\u52a8\u586b\u5145\n\u6574\u4e2a\u5c4f\u5e55( safeArea \u8303\u56f4\u5185)\u3002<\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p><strong>\u5e03\u5c40\u8fc7\u7a0b<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">1. SwiftUI \u5e03\u5c40\u7cfb\u7edf\u9996\u5148\u8be2\u95eeContentView:\u4f60\u62e5\u6709\u6574\u4e2a\u5c4f\u5e55\u5927\u5c0f\uff0c \u8fd9\u6b21\u5e03\u5c40\u4f60\u9700\u8981\u591a\u5927\u7a7a \u95f4? (\u7236View\u5efa\u8bae\u4e00\u4e2a\u5927\u5c0f)\n2. ContentView \u5e03\u5c40\u65e0\u5173\uff0c \u6240\u4ee5\u5b83\u8be2\u95ee background:\u4f60\u53ef\u4ee5\u62e5\u6709\u6574\u4e2a\u5c4f\u5e55\u5927\u5c0f \uff0c\u90a3\u4f60\u9700\u8981\u591a\u5927\u7a7a\u95f4?(\u7236View\u5efa\u8bae\u4e00\u4e2a\u5927\u5c0f)\n3. background \u4e5f\u5e03\u5c40\u65e0\u5173\uff0c \u6240\u4ee5\u5b83\u8be2\u95eeText:\u4f60\u53ef\u4ee5\u62e5\u6709\u6574\u4e2a\u5c4f\u5e55\u5927\u5c0f\uff0c \u90a3\u4f60\u9700\u8981\u591a\u5927\u7a7a\u95f4?(\u7236View\u5efa\u8bae\u4e00\u4e2a\u5927\u5c0f)\n4. Text \u91cc\u9762\u6709\u6587\u672c\u5185\u5bb9\uff0c \u5b57\u4f53\u9ed8\u8ba4\uff0c \u6240\u4ee5\u5b83\u5411 background\u53cd\u9988:\u53ea\u9700\u8981 x* y\u7684\u5927\u5c0f\u5373\u53ef\uff0c \u800c\u4e0d\u9700\u8981\u6574\u4e2a\u5c4f\u5e55\u5927\u5c0f \u3002(\u5b50View\u786e\u5b9a\u81ea\u5df1\u7684\u5927\u5c0f)\n5. background \u5411 ContentView \u53cd\u9988: \u9700\u8981 x* y\u7684\u5927\u5c0f\u3002\n6. ContentView \u5411 SwiftUI\u5e03\u5c40\u7cfb\u7edf\u53cd\u9988: \u9700\u8981 x* y\u7684\u5927\u5c0f\u3002\n7. SwiftUI \u5e03\u5c40\u7cfb\u7edf\u77e5\u9053\u4e86 ContentView \u9700\u8981\u7684\u7a7a\u95f4\u5927\u5c0f\u540e\u53d1\u73b0\u5c4f\u5e55\u5269\u4f59\u5f88\u591a\u7a7a\u95f4\uff0c\u4e8e\u662f\n\u4ee5\u9ed8\u8ba4\u65b9\u5f0f\u628a ContentView \u653e\u5728\u5c4f\u5e55\u7684\u5728\u4e2d\u95f4\u3002 (\u7236 View \u5c06\u5b50 View \u653e\u5728\u9002\u5f53\u7684\u4f4d\u7f6e)<\/pre>\n\n\n\n<p><strong>\u603b\u7ed3<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\u2022\u5728\u793a\u4f8b\u4e2d\uff0c ContentView \u4e2d\u7684\u9876\u7ea7 View \u662fbackground\uff0c Text \u6210\u4e3a background \u7684 \u5b50 View \u3002\n\u2022\u5f53\u6d89\u53ca\u5230 View \u53ca\u5176\u4fee\u9970\u7b26\u65f6\uff0c SwiftUI \u5e03\u5c40\u7cfb\u7edf\u4f1a\u6309\u7167\u4ece\u4e0b\u81f3\u4e0a\u7684\u987a\u5e8f\u5f00\u59cb\u5e03\u5c40\u3002<\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p><strong>\u6848\u4f8b2<\/strong><\/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=\"\">\/\/ \u6848\u5217\u4ee3\u78012\n\/\/ \u6b64\u65f6\u663e\u793a\u7684\u5185\u5bb9\u662f\u5728\u6848\u4f8b\u4e00\u4e2d\u7684\u57fa\u7840\u4e0a\u5728\u6587\u672c\u5468\u56f4\u591a\u4e86\u56db\u4e2a\u65b9\u5411\u7684 20 \u586b\u5145\u3002\nstruct ContentView: View {\n      var body: some View {\n      Text(\"Hello, SwiftUI!\") .padding(20).background(Color.orange)\n }\n }<\/pre>\n\n\n\n<p><strong>\u5e03\u5c40\u8fc7\u7a0b<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">1. SwiftUI \u5e03\u5c40\u7cfb\u7edf\u9996\u5148\u8be2\u95ee ContentView:\u4f60\u62e5\u6709\u6574\u4e2a\u5c4f\u5e55\u5927\u5c0f\uff0c\u8fd9\u6b21\u5e03\u5c40\u4f60\u9700\u8981\u591a\u5927\u7a7a \u95f4? (\u7236View\u5efa\u8bae\u4e00\u4e2a\u5927\u5c0f)\n2. ContentView \u5e03\u5c40\u65e0\u5173\uff0c\u6240\u4ee5\u5b83\u8be2\u95ee background:\u4f60\u53ef\u4ee5\u62e5\u6709\u6574\u4e2a\u5c4f\u5e55\u5927\u5c0f\uff0c\u90a3\u4f60\u9700\u8981\u591a\u5927\u7a7a\u95f4?(\u7236View\u5efa\u8bae\u4e00\u4e2a\u5927\u5c0f)\n3. background \u4e5f\u5e03\u5c40\u65e0\u5173\uff0c\u6240\u4ee5\u5b83\u8be2\u95ee padding:\u4f60\u53ef\u4ee5\u62e5\u6709\u6574\u4e2a\u5c4f\u5e55\u5927\u5c0f\uff0c\u90a3\u4f60\u9700\u8981\u591a\u5927\u7a7a\u95f4?(\u7236View\u5efa\u8bae\u4e00\u4e2a\u5927\u5c0f)\n4. padding \u6709\u503c 20\uff0c\u6240\u4ee5\u5b83\u9700\u8981\u6bcf\u4e2a\u65b9\u5411\u586b\u5145 20\uff0c\u7136\u540e\u5b83\u8be2\u95ee Text:\u4f60\u53ef\u4ee5\u62e5\u6709\u6574\u4e2a\u5c4f \u5e55\u53bb\u6389\u56db\u5468\u5404 20\u540e\u7684\u5927\u5c0f\uff0c\u90a3\u4f60\u9700\u8981\u591a\u5927\u7a7a\u95f4?(\u5b50View\u786e\u5b9a\u81ea\u5df1\u7684\u5927\u5c0f)\n5. Text \u91cc\u9762\u6709\u6587\u672c\u5185\u5bb9\uff0c\u5b57\u4f53\u9ed8\u8ba4\uff0c\u6240\u4ee5\u5b83\u5411 padding \u53cd\u9988:\u53ea\u9700\u8981 x * y \u7684\u5927\u5c0f\u5373\u53ef\uff0c\u800c\u4e0d\u9700\u8981\u6574\u4e2a\u5c4f\u5e55\u5927\u5c0f \u3002(\u5b50View\u786e\u5b9a\u81ea\u5df1\u7684\u5927\u5c0f)\n6. padding \u5411 background \u53cd\u9988:\u9700\u8981 x * y \u7684\u5927\u5c0f\uff0c\u7136\u540e\u5728\u56db\u5468\u5404\u586b\u5145 20\u3002\n7. background \u5411 ContentView \u53cd\u9988:\u9700\u8981 x * y \u7684\u5927\u5c0f\uff0c\u7136\u540e\u5728\u56db\u5468\u5404 \u586b\u5145 20\u3002\n8. ContentView \u5411 SwiftUI\u5e03\u5c40\u7cfb\u7edf\u53cd\u9988:\u9700\u8981 x * y  \u7684\u5927\u5c0f\uff0c\u7136\u540e\u5728\u56db\u5468 \u5404\u586b\u5145 20\u3002\n9. SwiftUI \u5e03\u5c40\u7cfb\u7edf\u77e5\u9053\u4e86 ContentView \u9700\u8981\u7684\u7a7a\u95f4\u5927\u5c0f\u540e\u53d1\u73b0\u5c4f\u5e55\u5269\u4f59\u5f88\u591a\u7a7a\u95f4\uff0c\n   \u4e8e\u662f\u4ee5\u9ed8\u8ba4\u65b9\u5f0f\u628a ContentView \u653e\u5728\u5c4f\u5e55\u7684\u5728\u4e2d\u95f4\u3002 (\u7236 View \u5c06\u5b50View \u653e\u5728\u9002\u5f53\u4f4d\u7f6e)<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>SwiftUI \u4f7f\u7528\u7075\u6d3b\u7684\u76d2\u5b50\u5e03\u5c40\u7cfb\u7edf\uff0cSwiftUI \u7684\u5e03\u5c40\u4e3b\u8981\u6b65\u9aa4\u5982\u4e0b: 1. \u7236 View \u4e3a\u5b50 Vie [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/314"}],"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=314"}],"version-history":[{"count":12,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/314\/revisions"}],"predecessor-version":[{"id":326,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/314\/revisions\/326"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=314"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=314"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=314"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}