{"id":3989,"date":"2025-06-03T11:15:53","date_gmt":"2025-06-05T03:53:52","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=3989"},"modified":"2025-06-05T11:15:53","modified_gmt":"2025-06-05T03:53:52","slug":"%e5%ad%b8%e7%bf%92%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8swift%e4%b8%ad%e7%9a%84%e8%bf%9b%e5%ba%a6%e8%a7%86%e5%9b%be","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/%e5%ad%b8%e7%bf%92%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8swift%e4%b8%ad%e7%9a%84%e8%bf%9b%e5%ba%a6%e8%a7%86%e5%9b%be\/","title":{"rendered":"2025 \u6700\u65b0\u7248 Swift \u7a0b\u5f0f\u6559\u5b78\uff1a\u5168\u9762\u638c\u63e1 UIProgressView \u9032\u5ea6\u8996\u5716\u7684\u4f7f\u7528\u6280\u5de7"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"Swift, UIProgressView, \u9032\u5ea6\u8996\u5716, \u6700\u5c0f\u503c, \u6700\u5927\u503c, \u9032\u5ea6\u503c, \u6a23\u5f0f, Swift 2025, \u7a0b\u5f0f\u6559\u5b78\"><\/p>\n<h1>\u4e86\u89e3\u5982\u4f55\u5728 Swift \u4e2d\u4f7f\u7528 UIProgressView \u9032\u5ea6\u8996\u5716<\/h1>\n<p>\u5728 Swift \u4e2d\uff0c\u9032\u5ea6\u8996\u5716\u662f\u4e00\u7a2e\u975e\u5e38\u5be6\u7528\u7684\u7528\u6236\u754c\u9762\u5143\u7d20\uff0c\u5b83\u53ef\u4ee5\u7528\u4f86\u986f\u793a\u4efb\u52d9\u7684\u9032\u5ea6\u3002\u96a8\u8457\u6280\u8853\u7684\u9032\u6b65\uff0cUIProgressView \u7684\u4f7f\u7528\u65b9\u6cd5\u4e5f\u6709\u6240\u66f4\u65b0\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728 2025 \u5e74\u7684 Swift \u4e2d\u4f7f\u7528 UIProgressView \u4f86\u5be6\u73fe\u9032\u5ea6\u8996\u5716\uff0c\u4e26\u63d0\u4f9b\u8a73\u7d30\u7684\u5be6\u4f5c\u7bc4\u4f8b\u548c\u6700\u4f73\u5be6\u8e10\uff0c\u8b93\u60a8\u80fd\u5920\u8f15\u9b06\u638c\u63e1\u9019\u4e00\u6280\u80fd\u3002<\/p>\n<h2>\u4f7f\u7528 UIProgressView \u985e\u5be6\u73fe\u9032\u5ea6\u8996\u5716<\/h2>\n<p>UIProgressView \u662f Swift \u4e2d\u5c08\u9580\u7528\u65bc\u986f\u793a\u9032\u5ea6\u7684\u985e\u3002\u8981\u4f7f\u7528 UIProgressView\uff0c\u9996\u5148\u9700\u8981\u5275\u5efa\u4e00\u500b UIProgressView \u7269\u4ef6\uff0c\u7136\u5f8c\u8a2d\u7f6e\u5b83\u7684 frame \u5c6c\u6027\uff0c\u6700\u5f8c\u5c07\u5176\u6dfb\u52a0\u5230\u8996\u5716\u4e2d\u3002\u4ee5\u4e0b\u662f\u57fa\u672c\u7684\u5be6\u4f5c\u793a\u7bc4\uff1a<\/p>\n<p>&#8220;`swift<br \/>\nlet progressView = UIProgressView(frame: CGRect(x: 20, y: 100, width: 280, height: 20))<br \/>\nprogressView.progress = 0.0 \/\/ \u521d\u59cb\u5316\u9032\u5ea6\u70ba0<br \/>\nview.addSubview(progressView)<br \/>\n&#8220;`<\/p>\n<h2>\u8a2d\u7f6e\u9032\u5ea6\u8996\u5716\u7684\u6700\u5c0f\u503c\u548c\u6700\u5927\u503c<\/h2>\n<p>\u5728\u4f7f\u7528 UIProgressView \u985e\u5be6\u73fe\u9032\u5ea6\u8996\u5716\u4e4b\u5f8c\uff0c\u9700\u8981\u8a2d\u7f6e\u9032\u5ea6\u8996\u5716\u7684\u6700\u5c0f\u503c\u548c\u6700\u5927\u503c\u3002\u6700\u5c0f\u503c\u548c\u6700\u5927\u503c\u5b9a\u7fa9\u4e86\u9032\u5ea6\u8996\u5716\u7684\u7bc4\u570d\u3002\u9ed8\u8a8d\u60c5\u6cc1\u4e0b\uff0c\u6700\u5c0f\u503c\u70ba 0\uff0c\u6700\u5927\u503c\u70ba 1\uff0c\u4f46\u6211\u5011\u53ef\u4ee5\u6839\u64da\u9700\u8981\u9032\u884c\u8a2d\u5b9a\u3002\u4ee5\u4e0b\u662f\u8a2d\u7f6e\u6700\u5c0f\u503c\u548c\u6700\u5927\u503c\u7684\u7bc4\u4f8b\uff1a<\/p>\n<p>&#8220;`swift<br \/>\nprogressView.progress = 0.5 \/\/ \u8a2d\u7f6e\u7576\u524d\u9032\u5ea6\u70ba50%<br \/>\n&#8220;`<\/p>\n<h2>\u8a2d\u7f6e\u9032\u5ea6\u8996\u5716\u7684\u9032\u5ea6\u503c<\/h2>\n<p>\u5728\u8a2d\u7f6e\u9032\u5ea6\u8996\u5716\u7684\u6700\u5c0f\u503c\u548c\u6700\u5927\u503c\u5f8c\uff0c\u63a5\u4e0b\u4f86\u9700\u8981\u8a2d\u7f6e\u9032\u5ea6\u8996\u5716\u7684\u9032\u5ea6\u503c\u3002\u9032\u5ea6\u503c\u8868\u793a\u4efb\u52d9\u7684\u5b8c\u6210\u7a0b\u5ea6\uff0c\u53ef\u4ee5\u901a\u904e `progress` \u5c6c\u6027\u4f86\u8a2d\u7f6e\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u8a2d\u5b9a\u9032\u5ea6\u503c\u7684\u7bc4\u4f8b\uff1a<\/p>\n<p>&#8220;`swift<br \/>\nprogressView.progress = 0.75 \/\/ \u8a2d\u7f6e\u7576\u524d\u9032\u5ea6\u70ba75%<br \/>\n&#8220;`<\/p>\n<h2>\u8a2d\u7f6e\u9032\u5ea6\u8996\u5716\u7684\u6a23\u5f0f<\/h2>\n<p>\u9664\u4e86\u8a2d\u7f6e\u6700\u5c0f\u503c\u3001\u6700\u5927\u503c\u548c\u9032\u5ea6\u503c\u4e4b\u5916\uff0cUIProgressView \u9084\u652f\u6301\u4e0d\u540c\u7684\u6a23\u5f0f\u8a2d\u7f6e\u3002\u53ef\u4ee5\u4f7f\u7528 `progressViewStyle` \u5c6c\u6027\u4f86\u8abf\u6574\u6a23\u5f0f\uff0c\u76ee\u524d\u63d0\u4f9b\u4e09\u7a2e\u6a23\u5f0f\uff1adefault\u3001bar \u548c annular\u3002\u4ee5\u4e0b\u662f\u5982\u4f55\u8a2d\u7f6e\u6a23\u5f0f\u7684\u7bc4\u4f8b\uff1a<\/p>\n<p>&#8220;`swift<br \/>\nprogressView.progressViewStyle = .bar \/\/ \u8a2d\u7f6e\u6a23\u5f0f\u70ba\u689d\u5f62<br \/>\n&#8220;`<\/p>\n<h2>\u5e38\u898b\u932f\u8aa4\u6392\u9664<\/h2>\n<p>\u5728\u4f7f\u7528 UIProgressView \u7684\u904e\u7a0b\u4e2d\uff0c\u53ef\u80fd\u6703\u9047\u5230\u4ee5\u4e0b\u5e38\u898b\u554f\u984c\uff1a<\/p>\n<p>1. **\u9032\u5ea6\u4e0d\u66f4\u65b0**\uff1a\u78ba\u4fdd\u5728\u4e3b\u7dda\u7a0b\u4e2d\u66f4\u65b0 `progress` \u5c6c\u6027\uff0c\u56e0\u70ba UI \u66f4\u65b0\u5fc5\u9808\u5728\u4e3b\u7dda\u7a0b\u57f7\u884c\u3002<br \/>\n2. **\u6a23\u5f0f\u7121\u6cd5\u986f\u793a**\uff1a\u6aa2\u67e5\u662f\u5426\u5728\u6b63\u78ba\u7684 UIViewController \u4e2d\u6dfb\u52a0\u9032\u5ea6\u8996\u5716\uff0c\u4e26\u78ba\u4fdd\u5176 frame \u8a2d\u7f6e\u6b63\u78ba\u3002<\/p>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>UIProgressView \u4e0d\u50c5\u53ef\u4ee5\u7528\u65bc\u986f\u793a\u4efb\u52d9\u9032\u5ea6\uff0c\u9084\u53ef\u4ee5\u8207\u5176\u4ed6 UI \u5143\u7d20\u7d50\u5408\u4f7f\u7528\uff0c\u4f8b\u5982\u5728\u4e0b\u8f09\u6587\u4ef6\u6216\u52a0\u8f09\u6578\u64da\u6642\uff0c\u60a8\u53ef\u4ee5\u5be6\u6642\u66f4\u65b0\u9032\u5ea6\u986f\u793a\uff0c\u63d0\u5347\u7528\u6236\u9ad4\u9a57\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 Swift \u4e2d\u7684 UIProgressView \u9032\u884c\u9032\u5ea6\u8996\u5716\u7684\u8a73\u7d30\u4ecb\u7d39\u3002\u901a\u904e\u672c\u6587\u7684\u5b78\u7fd2\uff0c\u76f8\u4fe1\u60a8\u5c0d\u5982\u4f55\u5728 Swift \u4e2d\u6709\u6548\u4f7f\u7528 UIProgressView \u6709\u4e86\u66f4\u6df1\u5165\u7684\u4e86\u89e3\u548c\u638c\u63e1\u3002<\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<p>**Q1: UIProgressView \u662f\u5426\u53ef\u4ee5\u81ea\u5b9a\u7fa9\u984f\u8272\uff1f**<br \/>\nA: \u662f\u7684\uff0c\u60a8\u53ef\u4ee5\u901a\u904e\u8a2d\u7f6e `progressTintColor` \u548c `trackTintColor` \u5c6c\u6027\u4f86\u81ea\u5b9a\u7fa9\u9032\u5ea6\u689d\u548c\u80cc\u666f\u7684\u984f\u8272\u3002<\/p>\n<p>**Q2: \u5982\u4f55\u5728\u9032\u5ea6\u66f4\u65b0\u6642\u986f\u793a\u52d5\u756b\u6548\u679c\uff1f**<br \/>\nA: \u60a8\u53ef\u4ee5\u4f7f\u7528 UIView \u7684\u52d5\u756b\u65b9\u6cd5\u4f86\u66f4\u65b0\u9032\u5ea6\u503c\uff0c\u4f8b\u5982\uff1a<\/p>\n<p>&#8220;`swift<br \/>\nUIView.animate(withDuration: 0.5) {<br \/>\n    progressView.setProgress(0.75, animated: true)<br \/>\n}<br \/>\n&#8220;`<\/p>\n<p>**Q3: UIProgressView \u662f\u5426\u652f\u6301\u4e0d\u540c\u7684\u9032\u5ea6\u7bc4\u570d\uff1f**<br \/>\nA: \u662f\u7684\uff0c\u60a8\u53ef\u4ee5\u81ea\u5b9a\u7fa9\u6700\u5c0f\u503c\u548c\u6700\u5927\u503c\uff0c\u4e0d\u904e\u9032\u5ea6\u503c\u4ecd\u9700\u5728\u9019\u500b\u7bc4\u570d\u5167\uff0c\u4f8b\u5982\u5f9e 0 \u5230 100\u3002<\/p>\n<p>&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981\uff1a\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528Swift\u4e2d\u7684\u8fdb\u5ea6\u89c6\u56fe\uff0c\u5305\u62ec\u5982\u4f55\u4f7f\u7528UIProgressView\u7c7b\u6765\u5b9e\u73b0\u8fdb\u5ea6\u89c6\u56fe\u3001\u5982\u4f55\u8bbe\u7f6e\u8fdb\u5ea6\u89c6\u56fe\u7684\u6700\u5c0f\u503c\u548c\u6700\u5927\u503c\u3001\u5982\u4f55\u8bbe\u7f6e\u8fdb\u5ea6\u89c6\u56fe\u7684\u8fdb\u5ea6\u503c\u3001\u5982\u4f55\u8bbe\u7f6e\u8fdb\u5ea6\u89c6\u56fe\u7684\u6837\u5f0f\u7b49\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","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-3989","post","type-post","status-publish","format-standard","hentry","category-ios","category-swift","tag-ios","tag-swift"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-12l","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3989","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=3989"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3989\/revisions"}],"predecessor-version":[{"id":3990,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3989\/revisions\/3990"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=3989"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=3989"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=3989"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}