{"id":7742,"date":"2025-06-02T14:07:36","date_gmt":"2025-06-05T06:55:35","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=7742"},"modified":"2025-06-05T14:07:36","modified_gmt":"2025-06-05T06:55:35","slug":"https-badgameshow-com-steven-514","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/https-badgameshow-com-steven-514\/","title":{"rendered":"2025 \u5e74\u6700\u65b0 SwiftUI \u5713\u5f62\u9032\u5ea6\u689d\u6559\u5b78\uff1a\u5f9e\u5165\u9580\u5230\u5be6\u4f5c"},"content":{"rendered":"<p>&#8220;`html<br \/>\n<meta name=\"keywords\" content=\"swift, SwiftUI, \u5713\u5f62\u9032\u5ea6\u689d, \u5713\u5f62\u9032\u5ea6\u689d\u6559\u5b78, SwiftUI \u6559\u5b78\"><\/p>\n<h2>\u7c21\u4ecb<\/h2>\n<p>\u5728 SwiftUI \u4e2d\u4f7f\u7528\u5713\u5f62\u9032\u5ea6\u689d\u662f\u4e00\u500b\u5f88\u6709\u8da3\u4e14\u5be6\u7528\u7684\u6280\u8853\uff0c\u5b83\u53ef\u4ee5\u5728\u61c9\u7528\u7a0b\u5f0f\u4e2d\u589e\u52a0\u4e00\u500b\u7f8e\u89c0\u7684\u9032\u5ea6\u6307\u793a\u5668\uff0c\u63d0\u5347\u7528\u6236\u9ad4\u9a57\u3002\u5728\u9019\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u5011\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528 Swift \u4f86\u5be6\u73fe\u5713\u5f62\u9032\u5ea6\u689d\uff0c\u4e26\u5c55\u793a\u5176\u5728 SwiftUI \u4e2d\u7684\u61c9\u7528\u3002<\/p>\n<h2>\u5275\u5efa SwiftUI \u9805\u76ee<\/h2>\n<p>\u9996\u5148\uff0c\u6211\u5011\u9700\u8981\u5275\u5efa\u4e00\u500b\u65b0\u7684 SwiftUI \u9805\u76ee\u3002\u6253\u958b Xcode\uff0c\u9078\u64c7\u300cCreate a new Xcode project\u300d\uff0c\u7136\u5f8c\u9078\u64c7\u300cApp\u300d\u4e26\u78ba\u4fdd\u9078\u64c7 SwiftUI \u4f5c\u70ba\u4ecb\u9762\u3002<\/p>\n<h2>\u5efa\u7acb CircularProgressView<\/h2>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u5c07\u5275\u5efa\u4e00\u500b\u65b0\u7684 SwiftUI \u8996\u5716\uff0c\u7a31\u4e4b\u70ba <strong>CircularProgressView<\/strong>\u3002\u5728\u9019\u500b\u8996\u5716\u4e2d\uff0c\u6211\u5011\u5c07\u5be6\u4f5c\u5713\u5f62\u9032\u5ea6\u689d\u3002<\/p>\n<h2>\u5b9a\u7fa9 CircularProgress \u7d50\u69cb<\/h2>\n<p>\u5728 <strong>CircularProgressView<\/strong> \u4e2d\uff0c\u6211\u5011\u9700\u8981\u5b9a\u7fa9\u4e00\u500b\u65b0\u7684 <strong>struct<\/strong>\uff0c\u7a31\u70ba <strong>CircularProgress<\/strong>\u3002\u9019\u500b\u7d50\u69cb\u5c07\u5305\u542b\u4e00\u500b <strong>progress<\/strong> \u5c6c\u6027\uff0c\u7528\u4f86\u8868\u793a\u9032\u5ea6\u503c\uff0c\u4ee5\u53ca\u4e00\u500b <strong>body<\/strong> \u5c6c\u6027\uff0c\u7528\u65bc\u7e6a\u88fd\u5713\u5f62\u9032\u5ea6\u689d\u3002<\/p>\n<p>&#8220;`swift<br \/>\nstruct CircularProgress: View {<br \/>\n    var progress: CGFloat<\/p>\n<p>    var body: some View {<br \/>\n        \/\/ \u7e6a\u88fd\u5713\u5f62\u9032\u5ea6\u689d<br \/>\n    }<br \/>\n}<br \/>\n&#8220;`<\/p>\n<h2>\u7e6a\u88fd\u5713\u5f62\u9032\u5ea6\u689d<\/h2>\n<p>\u73fe\u5728\uff0c\u6211\u5011\u53ef\u4ee5\u5728 <strong>CircularProgress<\/strong> \u4e2d\u7e6a\u88fd\u5713\u5f62\u9032\u5ea6\u689d\u3002\u6211\u5011\u5c07\u4f7f\u7528 SwiftUI \u7684 <strong>Circle<\/strong> \u985e\u578b\u4f86\u5275\u5efa\u5713\u5f62\uff0c\u4e26\u4f7f\u7528 <strong>AngularGradient<\/strong> \u4f86\u986f\u793a\u9032\u5ea6\u3002<\/p>\n<p>&#8220;`swift<br \/>\nstruct CircularProgress: View {<br \/>\n    var progress: CGFloat<\/p>\n<p>    var body: some View {<br \/>\n        Circle()<br \/>\n            .stroke(AngularGradient(gradient: Gradient(colors: [.blue, .green]), center: .center, startAngle: .zero, endAngle: .init(degrees: 360 * progress)), lineWidth: 10)<br \/>\n            .frame(width: 200, height: 200)<br \/>\n    }<br \/>\n}<br \/>\n&#8220;`<\/p>\n<h2>\u5728 CircularProgressView \u4e2d\u4f7f\u7528 CircularProgress<\/h2>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u9700\u8981\u5c07 <strong>CircularProgress<\/strong> \u6dfb\u52a0\u5230 <strong>CircularProgressView<\/strong> \u4e2d\uff0c\u4e26\u8a2d\u7f6e\u9032\u5ea6\u503c\u3002<\/p>\n<p>&#8220;`swift<br \/>\nstruct CircularProgressView: View {<br \/>\n    var body: some View {<br \/>\n        CircularProgress(progress: 0.5)<br \/>\n    }<br \/>\n}<br \/>\n&#8220;`<\/p>\n<p>\u5728\u9019\u88e1\uff0c\u6211\u5011\u5c07 <strong>progress<\/strong> \u5c6c\u6027\u8a2d\u7f6e\u70ba 0.5\uff0c\u9019\u5c07\u986f\u793a\u4e00\u500b\u534a\u5713\u5f62\u7684\u9032\u5ea6\u689d\u3002<\/p>\n<h2>\u932f\u8aa4\u6392\u9664<\/h2>\n<p>\u5982\u679c\u4f60\u5728\u986f\u793a\u5713\u5f62\u9032\u5ea6\u689d\u6642\u9047\u5230\u554f\u984c\uff0c\u8acb\u6aa2\u67e5\u4ee5\u4e0b\u5e7e\u9ede\uff1a<br \/>\n1. \u78ba\u4fdd\u4f60\u5df2\u7d93\u5c0e\u5165 SwiftUI \u6846\u67b6\u3002<br \/>\n2. \u78ba\u8a8d <strong>progress<\/strong> \u7684\u503c\u5728 0 \u5230 1 \u4e4b\u9593\u3002<br \/>\n3. \u6aa2\u67e5\u4f60\u7684 Xcode \u662f\u5426\u70ba\u6700\u65b0\u7248\u672c\uff0c\u4ee5\u907f\u514d\u7248\u672c\u76f8\u5bb9\u6027\u554f\u984c\u3002<\/p>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>\u4f60\u53ef\u4ee5\u5c07\u5713\u5f62\u9032\u5ea6\u689d\u61c9\u7528\u65bc\u5404\u7a2e\u5834\u666f\uff0c\u4f8b\u5982\uff1a<br \/>\n&#8211; \u986f\u793a\u4e0b\u8f09\u9032\u5ea6<br \/>\n&#8211; \u4efb\u52d9\u5b8c\u6210\u9032\u5ea6<br \/>\n&#8211; \u904b\u52d5\u5065\u8eab\u61c9\u7528\u7684\u76ee\u6a19\u9054\u6210<\/p>\n<h2>\u7d50\u8ad6<\/h2>\n<p>\u73fe\u5728\uff0c\u4f60\u5df2\u7d93\u5b78\u6703\u4e86\u5982\u4f55\u5728 SwiftUI \u4e2d\u4f7f\u7528\u5713\u5f62\u9032\u5ea6\u689d\uff0c\u4e26\u80fd\u5920\u9748\u6d3b\u61c9\u7528\u5230\u4f60\u7684\u61c9\u7528\u7a0b\u5f0f\u4e2d\uff0c\u63d0\u5347\u7528\u6236\u9ad4\u9a57\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/\u5728-SwiftUI-\u4e2d\u4f7f\u7528\u5713\u5f62\u9032\u5ea6\u689d_1676962818.9139788.webp\" alt=\"\u5728 SwiftUI \u4e2d\u4f7f\u7528\u5713\u5f62\u9032\u5ea6\u689d\" title=\"SwiftUI \u5713\u5f62\u9032\u5ea6\u689d\u793a\u4f8b\" width=\"1200\" height=\"628\"\/><\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<h3>1. \u5982\u4f55\u8abf\u6574\u5713\u5f62\u9032\u5ea6\u689d\u7684\u984f\u8272\uff1f<\/h3>\n<p>\u4f60\u53ef\u4ee5\u901a\u904e\u66f4\u6539 <strong>AngularGradient<\/strong> \u4e2d\u7684\u984f\u8272\u9663\u5217\u4f86\u8abf\u6574\u5713\u5f62\u9032\u5ea6\u689d\u7684\u984f\u8272\u3002\u4f8b\u5982\uff0c\u5c07 [.blue, .green] \u6539\u70ba [.red, .yellow]\u3002<\/p>\n<h3>2. \u5982\u4f55\u5728\u9032\u5ea6\u689d\u4e2d\u986f\u793a\u767e\u5206\u6bd4\uff1f<\/h3>\n<p>\u4f60\u53ef\u4ee5\u5728 <strong>CircularProgress<\/strong> \u7684 <strong>body<\/strong> \u4e2d\u6dfb\u52a0\u4e00\u500b\u6587\u672c\u8996\u5716\uff0c\u986f\u793a\u9032\u5ea6\u767e\u5206\u6bd4\uff0c\u4f8b\u5982\uff1a<br \/>\n&#8220;`swift<br \/>\nText(&#8220;\\(Int(progress * 100))%&#8221;)<br \/>\n    .font(.largeTitle)<br \/>\n    .foregroundColor(.black)<br \/>\n&#8220;`<\/p>\n<h3>3. \u5713\u5f62\u9032\u5ea6\u689d\u53ef\u4ee5\u8207\u5176\u4ed6\u8996\u5716\u7d50\u5408\u4f7f\u7528\u55ce\uff1f<\/h3>\n<p>\u662f\u7684\uff0c\u4f60\u53ef\u4ee5\u5c07\u5713\u5f62\u9032\u5ea6\u689d\u8207\u5176\u4ed6 SwiftUI \u8996\u5716\u7d50\u5408\u4f7f\u7528\uff0c\u5982\u6587\u672c\u3001\u5716\u50cf\u7b49\uff0c\u4f86\u5275\u5efa\u66f4\u8c50\u5bcc\u7684\u7528\u6236\u754c\u9762\u3002<br \/>\n&#8220;`<br \/>\n&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981:\u5728SwiftUI\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5713\u5f62\u9032\u5ea6\u689d\u4f86\u8868\u793a\u4efb\u52d9\u7684\u5b8c\u6210\u9032\u5ea6\uff0c\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528Swift\u8a9e\u8a00\u4f86\u5be6\u73fe\u5713\u5f62\u9032\u5ea6\u689d\u7684\u529f\u80fd\u3002<\/p>\n","protected":false},"author":1,"featured_media":7741,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[174,5],"tags":[173,9],"class_list":["post-7742","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ios","category-swift","tag-ios","tag-swift"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/\u5728-SwiftUI-\u4e2d\u4f7f\u7528\u5713\u5f62\u9032\u5ea6\u689d_1676962818.9139788.webp","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-20S","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7742","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/comments?post=7742"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7742\/revisions"}],"predecessor-version":[{"id":13091,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7742\/revisions\/13091"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/7741"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=7742"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=7742"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=7742"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}