{"id":6964,"date":"2025-05-31T13:51:29","date_gmt":"2025-06-05T06:20:29","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=6964"},"modified":"2025-06-05T13:51:29","modified_gmt":"2025-06-05T06:20:29","slug":"https-badgameshow-com-steven-158","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/https-badgameshow-com-steven-158\/","title":{"rendered":"Swift UIProgressView \u4f7f\u7528\u6307\u5357 (2025 \u66f4\u65b0) &#8211; \u5b8c\u6574\u9032\u5ea6\u689d\u6559\u5b78"},"content":{"rendered":"<p>&#8220;`html<br \/>\n<meta name=\"keywords\" content=\"swift, UIProgressView, \u9032\u5ea6\u689d, \u6559\u5b78, Swift \u9032\u5ea6\u689d, iOS \u958b\u767c\"><\/p>\n<h1>Swift UIProgressView \u4f7f\u7528\u6307\u5357 (2025 \u66f4\u65b0) &#8211; \u5b8c\u6574\u9032\u5ea6\u689d\u6559\u5b78<\/h1>\n<p>\u5728 Swift \u4e2d\uff0c\u6211\u5011\u53ef\u4ee5\u4f7f\u7528 <strong>UIProgressView<\/strong> \u4f86\u88fd\u4f5c\u9032\u5ea6\u689d\uff0c\u8a72\u5143\u4ef6\u975e\u5e38\u9069\u5408\u986f\u793a\u5404\u7a2e\u4efb\u52d9\u7684\u9032\u5ea6\uff0c\u4f8b\u5982\u6a94\u6848\u4e0b\u8f09\u6216\u4efb\u52d9\u57f7\u884c\u9032\u5ea6\u3002\u672c\u6587\u5c07\u8a73\u7d30\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528 UIProgressView \u4f86\u88fd\u4f5c\u9032\u5ea6\u689d\uff0c\u8b93\u4f60\u7684 App \u66f4\u52a0\u5b8c\u6574\u8207\u5c08\u696d\u3002<\/p>\n<h2>UIProgressView \u7c21\u4ecb<\/h2>\n<p>UIProgressView \u662f\u4e00\u500b\u7528\u4f86\u986f\u793a\u4efb\u52d9\u9032\u5ea6\u7684\u5143\u4ef6\u3002\u5b83\u5141\u8a31\u958b\u767c\u8005\u8a2d\u5b9a\u9032\u5ea6\u7684\u6700\u5c0f\u503c\u3001\u6700\u5927\u503c\u53ca\u7576\u524d\u503c\uff0c\u4e26\u652f\u6301\u4e0d\u540c\u7684\u986f\u793a\u6a23\u5f0f\uff0c\u4f8b\u5982\u689d\u72c0\u6216\u5713\u5f62\u6a23\u5f0f\u3002\u5728\u9032\u884c iOS \u958b\u767c\u6642\uff0c\u9019\u500b\u5143\u4ef6\u662f\u986f\u793a\u9032\u5ea6\u7684\u7406\u60f3\u9078\u64c7\u3002<\/p>\n<h2>\u5982\u4f55\u4f7f\u7528 UIProgressView<\/h2>\n<p>\u8981\u5728\u4f60\u7684\u61c9\u7528\u4e2d\u4f7f\u7528 UIProgressView\uff0c\u8acb\u6309\u7167\u4ee5\u4e0b\u6b65\u9a5f\u9032\u884c\uff1a<\/p>\n<p>1. **\u5728 Storyboard \u4e2d\u6dfb\u52a0 UIProgressView**:<br \/>\n   \u5728\u4f60\u7684 Storyboard \u4e2d\u62d6\u653e\u4e00\u500b UIProgressView \u5143\u4ef6\u5230\u4f60\u7684 ViewController \u4e2d\u3002\u63a5\u8457\uff0c\u8a18\u5f97\u5728 ViewController \u4e2d\u5efa\u7acb\u4e00\u500b IBOutlet \u4f86\u9023\u63a5\u9019\u500b\u5143\u4ef6\uff1a<\/p>\n<p>   &#8220;`swift<br \/>\n   @IBOutlet weak var progressView: UIProgressView!<br \/>\n   &#8220;`<\/p>\n<p>2. **\u8a2d\u5b9a\u9032\u5ea6\u689d\u7684\u503c**:<br \/>\n   \u4f60\u53ef\u4ee5\u900f\u904e\u4ee5\u4e0b\u7a0b\u5f0f\u78bc\u4f86\u8a2d\u5b9a UIProgressView \u7684\u6700\u5c0f\u503c\u3001\u6700\u5927\u503c\u548c\u7576\u524d\u7684\u503c\uff1a<\/p>\n<p>   &#8220;`swift<br \/>\n   progressView.progress = 0.5 \/\/ \u7576\u524d\u9032\u5ea6<br \/>\n   progressView.minimumValue = 0 \/\/ \u6700\u5c0f\u503c<br \/>\n   progressView.maximumValue = 1 \/\/ \u6700\u5927\u503c<br \/>\n   &#8220;`<\/p>\n<p>3. **\u8a2d\u5b9a\u9032\u5ea6\u689d\u7684\u6a23\u5f0f**:<br \/>\n   UIProgressView \u63d0\u4f9b\u4e86\u5e7e\u7a2e\u6a23\u5f0f\u9078\u64c7\uff0c\u4f60\u53ef\u4ee5\u9078\u64c7\u689d\u72c0\u6216\u5713\u5f62\u6a23\u5f0f\uff1a<\/p>\n<p>   &#8220;`swift<br \/>\n   progressView.progressViewStyle = .bar \/\/ \u689d\u72c0\u6a23\u5f0f<br \/>\n   &#8220;`<\/p>\n<h2>\u9032\u5ea6\u66f4\u65b0\u8207\u932f\u8aa4\u6392\u9664<\/h2>\n<p>\u5728\u5be6\u4f5c\u904e\u7a0b\u4e2d\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u6839\u64da\u4efb\u52d9\u7684\u9032\u5ea6\u4e0d\u65b7\u66f4\u65b0 UIProgressView\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u7bc4\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u5728\u4e0b\u8f09\u904e\u7a0b\u4e2d\u66f4\u65b0\u9032\u5ea6\u689d\uff1a<\/p>\n<p>&#8220;`swift<br \/>\nfunc downloadFile() {<br \/>\n    let totalBytes = 100 \/\/ \u5047\u8a2d\u7e3d\u5927\u5c0f\u70ba 100 MB<br \/>\n    for downloadedBytes in 0&#8230;totalBytes {<br \/>\n        let progress = Float(downloadedBytes) \/ Float(totalBytes)<br \/>\n        DispatchQueue.main.async {<br \/>\n            self.progressView.setProgress(progress, animated: true)<br \/>\n        }<br \/>\n        \/\/ \u6a21\u64ec\u4e0b\u8f09\u5ef6\u9072<br \/>\n        Thread.sleep(forTimeInterval: 0.1)<br \/>\n    }<br \/>\n}<br \/>\n&#8220;`<\/p>\n<p>\u82e5\u9032\u5ea6\u689d\u7121\u6cd5\u986f\u793a\u6b63\u78ba\u7684\u9032\u5ea6\uff0c\u8acb\u6aa2\u67e5\u4ee5\u4e0b\u4e8b\u9805\uff1a<br \/>\n&#8211; \u78ba\u4fdd `minimumValue` \u548c `maximumValue` \u88ab\u6b63\u78ba\u8a2d\u5b9a\u3002<br \/>\n&#8211; \u78ba\u8a8d\u9032\u5ea6\u503c\u5728 0 \u5230 1 \u4e4b\u9593\u3002<\/p>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>\u9664\u4e86\u57fa\u672c\u7684\u4f7f\u7528\u65b9\u6cd5\uff0cUIProgressView \u9084\u53ef\u4ee5\u7528\u65bc\u5be6\u73fe\u66f4\u8907\u96dc\u7684\u529f\u80fd\uff0c\u4f8b\u5982\uff1a<br \/>\n&#8211; \u5728\u80cc\u666f\u4efb\u52d9\u4e2d\u986f\u793a\u9032\u5ea6<br \/>\n&#8211; \u8207\u5176\u4ed6 UI \u5143\u4ef6\u7d50\u5408\uff0c\u4f8b\u5982 UIButton \u4f86\u89f8\u767c\u9032\u5ea6\u66f4\u65b0<br \/>\n&#8211; \u4f7f\u7528\u52d5\u756b\u6548\u679c\u63d0\u9ad8\u7528\u6236\u9ad4\u9a57<\/p>\n<h2>\u7d50\u8ad6<\/h2>\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u8a73\u7d30\u4ecb\u7d39\u4e86\u5982\u4f55\u4f7f\u7528 UIProgressView \u4f86\u88fd\u4f5c\u9032\u5ea6\u689d\uff0c\u4e26\u63d0\u4f9b\u4e86\u5be6\u4f5c\u7bc4\u4f8b\u8207\u5e38\u898b\u932f\u8aa4\u6392\u9664\u65b9\u6cd5\u3002UIProgressView \u4e0d\u50c5\u80fd\u5920\u986f\u793a\u4efb\u52d9\u7684\u9032\u5ea6\uff0c\u9084\u80fd\u63d0\u5347\u7528\u6236\u7684\u64cd\u4f5c\u9ad4\u9a57\uff0c\u8b93\u4f60\u7684 App \u986f\u5f97\u66f4\u52a0\u5c08\u696d\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-UIProgressView\u4f7f\u7528\ud83d\udcc8-\u9032\u5ea6\u689d\u6559\u5b78_1675399296.468143.webp\" alt=\"Swift UIProgressView\u4f7f\u7528\ud83d\udcc8 - \u9032\u5ea6\u689d\u6559\u5b78\" title=\"Swift UIProgressView\u3001\u9032\u5ea6\u689d\u6559\u5b78\u3001Swift \u9032\u5ea6\u689d\u3001UIProgressView \u5c6c\u6027\u3001\u66f4\u65b0\u9032\u5ea6\u689d\" width=\"1200\" height=\"628\"\/><\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<h3>Q1: UIProgressView \u53ea\u80fd\u986f\u793a\u5f9e 0 \u5230 1 \u7684\u9032\u5ea6\u55ce\uff1f<\/h3>\n<p>A1: \u662f\u7684\uff0cUIProgressView \u7684\u9032\u5ea6\u662f\u4ee5 0 \u5230 1 \u7684\u6bd4\u4f8b\u4f86\u986f\u793a\u7684\u3002\u4f60\u53ef\u4ee5\u900f\u904e\u8a2d\u5b9a\u6700\u5c0f\u503c\u548c\u6700\u5927\u503c\u4f86\u6539\u8b8a\u9019\u500b\u7bc4\u570d\u3002<\/p>\n<h3>Q2: \u5982\u4f55\u8b93\u9032\u5ea6\u689d\u66f4\u65b0\u6642\u5e36\u6709\u52d5\u756b\u6548\u679c\uff1f<\/h3>\n<p>A2: \u4f60\u53ef\u4ee5\u4f7f\u7528 `setProgress(_:animated:)` \u65b9\u6cd5\u4f86\u8a2d\u5b9a\u9032\u5ea6\uff0c\u4e26\u5c07 animated \u53c3\u6578\u8a2d\u70ba true\uff0c\u4ee5\u5be6\u73fe\u5e73\u6ed1\u7684\u52d5\u756b\u6548\u679c\u3002<\/p>\n<h3>Q3: UIProgressView \u53ef\u4ee5\u8207\u5176\u4ed6\u5143\u4ef6\u4e00\u8d77\u4f7f\u7528\u55ce\uff1f<\/h3>\n<p>A3: \u662f\u7684\uff0c\u4f60\u53ef\u4ee5\u5c07 UIProgressView \u8207 UIButton \u6216\u5176\u4ed6 UI \u5143\u4ef6\u7d50\u5408\u4f7f\u7528\uff0c\u4ee5\u5be6\u73fe\u66f4\u52a0\u4e92\u52d5\u7684\u529f\u80fd\uff0c\u4f8b\u5982\u5728\u6309\u9215\u9ede\u64ca\u6642\u958b\u59cb\u4e0b\u8f09\u4e26\u66f4\u65b0\u9032\u5ea6\u689d\u3002<\/p>\n<p>&#8220;`<br \/>\n&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1a\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528SwiftUIProgressView\u4f86\u5275\u5efa\u9032\u5ea6\u689d\uff0c\u4e26\u8a73\u7d30\u89e3\u91cb\u5982\u4f55\u8a2d\u7f6e\u9032\u5ea6\u689d\u7684\u5c6c\u6027\uff0c\u4ee5\u53ca\u5982\u4f55\u66f4\u65b0\u9032\u5ea6\u689d\u7684\u503c\u3002<\/p>\n","protected":false},"author":1,"featured_media":6963,"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-6964","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\/Swift-UIProgressView\u4f7f\u7528\ud83d\udcc8-\u9032\u5ea6\u689d\u6559\u5b78_1675399296.468143.webp","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1Ok","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6964","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=6964"}],"version-history":[{"count":5,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6964\/revisions"}],"predecessor-version":[{"id":13586,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/6964\/revisions\/13586"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/6963"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=6964"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=6964"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=6964"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}