{"id":3985,"date":"2025-06-04T11:42:25","date_gmt":"2025-06-05T03:53:25","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=3985"},"modified":"2025-06-05T11:42:25","modified_gmt":"2025-06-05T03:53:25","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%e9%a1%b5%e9%9d%a2%e6%8e%a7%e5%88%b6%e5%99%a8","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%e9%a1%b5%e9%9d%a2%e6%8e%a7%e5%88%b6%e5%99%a8\/","title":{"rendered":"\u5168\u9762\u638c\u63e1 Swift \u4e2d\u7684 UIPageControl\uff1a\u5f9e\u57fa\u790e\u5230\u6700\u4f73\u5be6\u8e10\uff082025 \u6700\u65b0\u6559\u5b78\uff09"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"Swift, UIPageControl, \u9875\u9762\u63a7\u5236\u5668, \u4e8b\u4ef6\u5904\u7406\u65b9\u6cd5, SEO\u512a\u5316\"><\/p>\n<h1>\u5168\u9762\u638c\u63e1 Swift \u4e2d\u7684 UIPageControl\uff1a\u5f9e\u57fa\u790e\u5230\u6700\u4f73\u5be6\u8e10<\/h1>\n<p>\u5728 Swift \u4e2d\uff0c**UIPageControl** \u662f\u4e00\u7a2e\u7528\u65bc\u7ba1\u7406\u548c\u63a7\u5236\u591a\u500b\u8996\u5716\u63a7\u5236\u5668\u7684\u6280\u8853\u3002\u5b83\u80fd\u5920\u5e6b\u52a9\u958b\u767c\u8005\u5be6\u73fe\u8996\u5716\u63a7\u5236\u5668\u4e4b\u9593\u7684\u5207\u63db\uff0c\u5f9e\u800c\u69cb\u5efa\u8907\u96dc\u7684\u7528\u6236\u754c\u9762\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e\u5982\u4f55\u4f7f\u7528 Swift \u4e2d\u7684 UIPageControl\uff0c\u5305\u62ec\u8a2d\u7f6e\u9801\u9762\u7e3d\u6578\u3001\u7576\u524d\u9801\u78bc\u3001\u4e8b\u4ef6\u8655\u7406\u65b9\u6cd5\u7b49\uff0c\u4e26\u63d0\u4f9b\u5be6\u4f5c\u7bc4\u4f8b\u548c\u6700\u4f73\u5be6\u8e10\u3002<\/p>\n<h2>\u4f7f\u7528 UIPageControl \u985e\u5be6\u73fe\u9801\u9762\u63a7\u5236\u5668<\/h2>\n<p>**UIPageControl** \u985e\u662f\u4e00\u500b\u7528\u65bc\u5be6\u73fe\u9801\u9762\u63a7\u5236\u5668\u7684\u6838\u5fc3\u7d44\u4ef6\u3002\u8981\u4f7f\u7528\u6b64\u985e\uff0c\u9996\u5148\u9700\u5728 Xcode \u4e2d\u5275\u5efa\u4e00\u500b\u65b0\u7684\u9805\u76ee\uff0c\u7136\u5f8c\u5728\u754c\u9762\u4e0a\u6dfb\u52a0 UIPageControl \u7684\u5be6\u4f8b\u3002<\/p>\n<p>&#8220;`swift<br \/>\nlet pageControl = UIPageControl()<br \/>\n&#8220;`<\/p>\n<p>### \u8a2d\u7f6e\u9801\u9762\u63a7\u5236\u5668\u7684\u7e3d\u9801\u6578\u548c\u7576\u524d\u9801\u78bc<\/p>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u9700\u8981\u8a2d\u7f6e\u9801\u9762\u63a7\u5236\u5668\u7684\u7e3d\u9801\u6578\u548c\u7576\u524d\u9801\u78bc\uff1a<\/p>\n<p>&#8220;`swift<br \/>\npageControl.numberOfPages = 5<br \/>\npageControl.currentPage = 0<br \/>\n&#8220;`<\/p>\n<p>### \u6dfb\u52a0\u4e8b\u4ef6\u8655\u7406\u65b9\u6cd5<\/p>\n<p>\u70ba\u4e86\u8b93\u9801\u9762\u63a7\u5236\u5668\u97ff\u61c9\u7528\u6236\u7684\u64cd\u4f5c\uff0c\u6211\u5011\u9084\u9700\u8981\u6dfb\u52a0\u4e8b\u4ef6\u8655\u7406\u65b9\u6cd5\uff1a<\/p>\n<p>&#8220;`swift<br \/>\npageControl.addTarget(self, action: #selector(pageControlValueChanged(_:)), for: .valueChanged)<br \/>\n&#8220;`<\/p>\n<p>\u5728\u4e8b\u4ef6\u8655\u7406\u65b9\u6cd5\u4e2d\uff0c\u6211\u5011\u53ef\u4ee5\u6839\u64da\u7528\u6236\u6240\u9078\u7684\u9801\u78bc\u5be6\u73fe\u8996\u5716\u63a7\u5236\u5668\u4e4b\u9593\u7684\u5207\u63db\uff1a<\/p>\n<p>&#8220;`swift<br \/>\n@objc func pageControlValueChanged(_ sender: UIPageControl) {<br \/>\n    \/\/ \u6839\u64da sender.currentPage \u5207\u63db\u8996\u5716\u63a7\u5236\u5668<br \/>\n    let selectedIndex = sender.currentPage<br \/>\n    \/\/ \u4f8b\u5982\uff0c\u4f7f\u7528 UIPageViewController \u5207\u63db\u8996\u5716<br \/>\n}<br \/>\n&#8220;`<\/p>\n<p>\u9019\u6bb5\u4ee3\u78bc\u5c07\u6839\u64da\u7528\u6236\u7684\u9078\u64c7\u5207\u63db\u5230\u6307\u5b9a\u7684\u8996\u5716\u63a7\u5236\u5668\u3002<\/p>\n<h2>\u932f\u8aa4\u6392\u9664\u8207\u5e38\u898b\u554f\u984c<\/h2>\n<p>\u5728\u4f7f\u7528 UIPageControl \u6642\uff0c\u958b\u767c\u8005\u53ef\u80fd\u6703\u9047\u5230\u4ee5\u4e0b\u5e7e\u500b\u5e38\u898b\u554f\u984c\uff1a<\/p>\n<p>1. **\u7121\u6cd5\u5207\u63db\u9801\u9762**\uff1a\u78ba\u4fdd\u5df2\u6b63\u78ba\u8a2d\u7f6e target \u548c action\uff0c\u4e26\u4e14 UIPageControl \u7684 currentPage \u5c6c\u6027\u80fd\u5920\u53cd\u6620\u7576\u524d\u9801\u9762\u3002<br \/>\n2. **UIPageControl \u4e0d\u986f\u793a**\uff1a\u6aa2\u67e5 UIPageControl \u662f\u5426\u5df2\u6dfb\u52a0\u5230\u8996\u5716\u4e2d\uff0c\u4e26\u4e14\u8a2d\u7f6e\u4e86\u5408\u9069\u7684\u7d04\u675f\u689d\u4ef6\u3002<\/p>\n<h2>SEO \u512a\u5316<\/h2>\n<p>\u4f7f\u7528 UIPageControl \u5be6\u73fe\u9801\u9762\u63a7\u5236\u5668\u5f8c\uff0c\u70ba\u4e86\u8b93\u641c\u7d22\u5f15\u64ce\u80fd\u5920\u66f4\u597d\u5730\u6293\u53d6\u548c\u6392\u540d\uff0c\u958b\u767c\u8005\u61c9\u8003\u616e\u4ee5\u4e0b SEO \u512a\u5316\u7b56\u7565\uff1a<\/p>\n<p>&#8211; **\u5408\u7406\u4f7f\u7528\u95dc\u9375\u8a5e**\uff1a\u5728\u6a19\u984c\u548c\u5167\u5bb9\u4e2d\u81ea\u7136\u5730\u52a0\u5165\u76f8\u95dc\u95dc\u9375\u8a5e\u3002<br \/>\n&#8211; **\u7d50\u69cb\u5316\u6a19\u7c64**\uff1a\u4f7f\u7528\u9069\u7576\u7684\u6a19\u7c64\uff08\u5982 `<\/p>\n<h2>`\u3001`<\/p>\n<h3>`\uff09\u4f86\u7d44\u7e54\u5167\u5bb9\uff0c\u5e6b\u52a9\u641c\u7d22\u5f15\u64ce\u7406\u89e3\u9801\u9762\u7d50\u69cb\u3002<br \/>\n&#8211; **\u5167\u90e8\u9023\u7d50**\uff1a\u5728\u6587\u7ae0\u4e2d\u6dfb\u52a0\u5167\u90e8\u9023\u7d50\uff0c\u4ee5\u63d0\u9ad8\u7db2\u7ad9\u7684\u6574\u9ad4 SEO \u6548\u679c\u3002<\/p>\n<p>\u901a\u904e\u4ee5\u4e0a\u6b65\u9a5f\uff0c\u958b\u767c\u8005\u4e0d\u50c5\u80fd\u5920\u6709\u6548\u4f7f\u7528 Swift \u4e2d\u7684 UIPageControl\uff0c\u9084\u80fd\u63d0\u5347\u7db2\u7ad9\u7684\u641c\u7d22\u6392\u540d\uff0c\u5f9e\u800c\u5438\u5f15\u66f4\u591a\u7684\u8a2a\u554f\u8005\u3002<\/p>\n<h2>\u7d50\u8a9e<\/h2>\n<p>\u638c\u63e1 Swift \u4e2d\u7684 UIPageControl \u662f\u6bcf\u4f4d iOS \u958b\u767c\u8005\u7684\u5fc5\u7d93\u4e4b\u8def\u3002\u96a8\u8457\u6280\u8853\u7684\u9032\u6b65\u548c\u66f4\u65b0\uff0c\u4fdd\u6301\u5b78\u7fd2\u548c\u5be6\u8e10\u5c07\u6709\u52a9\u65bc\u63d0\u5347\u958b\u767c\u80fd\u529b\u548c\u7528\u6236\u9ad4\u9a57\u3002<\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<p>**Q1: UIPageControl \u53ef\u4ee5\u986f\u793a\u591a\u5c11\u9801\u9762\uff1f**<br \/>\nA1: UIPageControl \u7684\u9801\u9762\u6578\u91cf\u53ef\u4ee5\u6839\u64da\u9700\u6c42\u8a2d\u7f6e\uff0c\u7406\u8ad6\u4e0a\u6c92\u6709\u4e0a\u9650\uff0c\u4f46\u5efa\u8b70\u6839\u64da\u7528\u6236\u754c\u9762\u8a2d\u8a08\u5408\u7406\u63a7\u5236\u6578\u91cf\u3002<\/p>\n<p>**Q2: \u5982\u4f55\u5728 UIPageControl \u4e2d\u81ea\u5b9a\u7fa9\u9801\u9762\u6307\u793a\u5668\u7684\u6a23\u5f0f\uff1f**<br \/>\nA2: \u53ef\u4ee5\u901a\u904e\u8a2d\u7f6e UIPageControl \u7684 `pageIndicatorTintColor` \u548c `currentPageIndicatorTintColor` \u4f86\u81ea\u5b9a\u7fa9\u6a23\u5f0f\u3002<\/p>\n<p>**Q3: \u5982\u679c\u6211\u60f3\u8981\u4f7f\u7528\u81ea\u5b9a\u7fa9\u52d5\u756b\u6548\u679c\uff0c\u61c9\u8a72\u600e\u9ebc\u505a\uff1f**<br \/>\nA3: \u53ef\u4ee5\u7d50\u5408 UIPageViewController \u4f86\u5be6\u73fe\u81ea\u5b9a\u7fa9\u7684\u5207\u63db\u52d5\u756b\uff0c\u9019\u6a23\u80fd\u5920\u63d0\u4f9b\u66f4\u597d\u7684\u7528\u6236\u9ad4\u9a57\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\u9875\u9762\u63a7\u5236\u5668\uff0c\u5305\u62ec\u5982\u4f55\u4f7f\u7528UIPageControl\u7c7b\u6765\u5b9e\u73b0\u9875\u9762\u63a7\u5236\u5668\u3001\u5982\u4f55\u8bbe\u7f6e\u9875\u9762\u63a7\u5236\u5668\u7684\u603b\u9875\u6570\u548c\u5f53\u524d\u9875\u7801\u3001\u5982\u4f55\u4e3a\u9875\u9762\u63a7\u5236\u5668\u6dfb\u52a0\u4e8b\u4ef6\u5904\u7406\u65b9\u6cd5\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-3985","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-12h","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3985","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=3985"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3985\/revisions"}],"predecessor-version":[{"id":3986,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/3985\/revisions\/3986"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=3985"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=3985"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=3985"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}