{"id":7164,"date":"2025-06-03T15:01:01","date_gmt":"2025-06-05T07:25:01","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=7164"},"modified":"2025-06-05T15:01:01","modified_gmt":"2025-06-05T07:25:01","slug":"https-badgameshow-com-steven-255","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/https-badgameshow-com-steven-255\/","title":{"rendered":"\u6700\u65b0 Swift UIPageControl \u6559\u5b78\uff1a2025 \u5e74\u6700\u4f73\u5be6\u8e10\u8207\u5be6\u4f5c\u7bc4\u4f8b"},"content":{"rendered":"<p><meta name=\"keywords\" content=\"swift, UIPageControl, \u9801\u6578\u63a7\u5236\u5668, Swift \u6559\u5b78, UIPageControl \u4f7f\u7528\u65b9\u6cd5\"><\/p>\n<h1>\u6700\u65b0 Swift UIPageControl \u6559\u5b78\uff1a2025 \u5e74\u6700\u4f73\u5be6\u8e10\u8207\u5be6\u4f5c\u7bc4\u4f8b<\/h1>\n<p>Swift UIPageControl \ud83d\udcd6 \u662f\u4e00\u500b\u975e\u5e38\u5be6\u7528\u7684\u9801\u6578\u63a7\u5236\u5668\uff0c\u8b93\u958b\u767c\u8005\u8f15\u9b06\u5728 App \u4e2d\u6dfb\u52a0\u9801\u6578\u63a7\u5236\u529f\u80fd\uff0c\u4f7f\u7528\u8005\u53ef\u4ee5\u65b9\u4fbf\u5730\u7ffb\u9801\uff0c\u63d0\u5347\u95b1\u8b80\u9ad4\u9a57\u30022025 \u5e74\u7684\u65b0\u8a9e\u6cd5\u548c\u6700\u4f73\u5be6\u8e10\u8b93\u9019\u500b\u529f\u80fd\u66f4\u52a0\u5f37\u5927\u548c\u6613\u7528\u3002<\/p>\n<h2>UIPageControl \u7c21\u4ecb<\/h2>\n<p>UIPageControl \u80fd\u5920\u8a2d\u5b9a\u6bcf\u4e00\u9801\u7684\u5716\u7247\u548c\u6587\u5b57\uff0c\u4f7f\u60a8\u7684 App \u5167\u5bb9\u66f4\u52a0\u8c50\u5bcc\u4e14\u6709\u8da3\u3002\u900f\u904e UIPageControl\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u5be6\u73fe\u591a\u9801\u5167\u5bb9\u7684\u4fbf\u6377\u5c0e\u822a\u3002<\/p>\n<h2>\u5982\u4f55\u5728 Swift \u4e2d\u4f7f\u7528 UIPageControl<\/h2>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u5c07\u4e00\u6b65\u6b65\u4ecb\u7d39\u5982\u4f55\u5728 Swift \u4e2d\u4f7f\u7528 UIPageControl\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u5be6\u4f5c\u7bc4\u4f8b\u3002<\/p>\n<h3>\u6b65\u9a5f 1: \u5275\u5efa UIPageControl<\/h3>\n<p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u5728\u60a8\u7684\u8996\u5716\u63a7\u5236\u5668\u4e2d\u5275\u5efa UIPageControl \u7269\u4ef6\u3002\u4ee5\u4e0b\u662f\u5275\u5efa\u548c\u8a2d\u5b9a UIPageControl \u7684\u57fa\u672c\u7a0b\u5f0f\u78bc\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">let pageControl = UIPageControl()\npageControl.numberOfPages = 5\npageControl.currentPage = 0\npageControl.pageIndicatorTintColor = UIColor.lightGray\npageControl.currentPageIndicatorTintColor = UIColor.black<\/code><\/pre>\n<h3>\u6b65\u9a5f 2: \u6dfb\u52a0\u52d5\u4f5c<\/h3>\n<p>\u63a5\u8457\uff0c\u4f7f\u7528 <strong>addTarget<\/strong> \u65b9\u6cd5\u70ba UIPageControl \u6dfb\u52a0\u52d5\u4f5c\uff0c\u8b93\u5b83\u80fd\u5920\u97ff\u61c9\u4f7f\u7528\u8005\u7684\u4ea4\u4e92\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">pageControl.addTarget(self, action: #selector(pageChanged), for: .valueChanged)<\/code><\/pre>\n<h3>\u6b65\u9a5f 3: \u8a2d\u5b9a\u9801\u9762\u5167\u5bb9<\/h3>\n<p>\u6700\u5f8c\uff0c\u60a8\u53ef\u4ee5\u7528 <strong>setViewControllers<\/strong> \u65b9\u6cd5\u4f86\u8a2d\u5b9a\u6bcf\u4e00\u9801\u7684\u5167\u5bb9\uff0c\u9019\u88e1\u662f\u4e00\u500b\u7bc4\u4f8b\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">let viewController1 = UIViewController() \/\/ \u70ba\u6bcf\u9801\u5275\u5efa\u8996\u5716\u63a7\u5236\u5668\nlet viewController2 = UIViewController()\nlet viewController3 = UIViewController()\npageControl.setViewControllers([viewController1, viewController2, viewController3], direction: .forward, animated: true, completion: nil)<\/code><\/pre>\n<h2>\u932f\u8aa4\u6392\u9664\u6280\u5de7<\/h2>\n<p>\u5728\u4f7f\u7528 UIPageControl \u6642\uff0c\u53ef\u80fd\u6703\u9047\u5230\u4e00\u4e9b\u5e38\u898b\u932f\u8aa4\uff0c\u4f8b\u5982\u7121\u6cd5\u6b63\u78ba\u66f4\u65b0\u7576\u524d\u9801\u6578\u6216\u9801\u9762\u5167\u5bb9\u4e0d\u986f\u793a\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u6392\u9664\u932f\u8aa4\u7684\u6280\u5de7\uff1a<\/p>\n<ul>\n<li>\u78ba\u8a8d <strong>numberOfPages<\/strong> \u662f\u5426\u6b63\u78ba\u8a2d\u5b9a\uff0c\u4e26\u8207\u60a8\u5be6\u969b\u7684\u9801\u9762\u6578\u91cf\u76f8\u7b26\u3002<\/li>\n<li>\u6aa2\u67e5 <strong>currentPage<\/strong> \u7684\u503c\u662f\u5426\u5728\u6709\u6548\u7bc4\u570d\u5167\u3002<\/li>\n<li>\u78ba\u4fdd\u6240\u6709\u7684\u8996\u5716\u63a7\u5236\u5668\u90fd\u5df2\u6b63\u78ba\u521d\u59cb\u5316\u548c\u8a2d\u5b9a\u3002<\/li>\n<\/ul>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>UIPageControl \u4e0d\u50c5\u53ef\u4ee5\u7528\u65bc\u7c21\u55ae\u7684\u9801\u9762\u7ffb\u8f49\uff0c\u9084\u53ef\u4ee5\u8207\u5176\u4ed6\u8996\u5716\u63a7\u5236\u5668\u7d50\u5408\u4f7f\u7528\uff0c\u4f8b\u5982\u8207 <strong>UICollectionView<\/strong> \u6216 <strong>UITableView<\/strong> \u7d50\u5408\uff0c\u5275\u5efa\u66f4\u8c50\u5bcc\u7684\u7528\u6236\u9ad4\u9a57\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-UIPageControl-\ud83d\udcd6\u9801\u6578\u63a7\u5236\u5668\uff01_1675403782.9674518.webp\" alt=\"Swift UIPageControl \ud83d\udcd6\u9801\u6578\u63a7\u5236\u5668\uff01\" title=\"Swift UIPageControl\u3001\u9801\u6578\u63a7\u5236\u3001UIPageControl\u4f7f\u7528\u65b9\u6cd5\" width=\"1200\" height=\"628\"\/><\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<h3>1. UIPageControl \u5982\u4f55\u8207 UIScrollView \u4e00\u8d77\u4f7f\u7528\uff1f<\/h3>\n<p>\u60a8\u53ef\u4ee5\u5c07 UIPageControl \u7684 <strong>currentPage<\/strong> \u5c6c\u6027\u8207 UIScrollView \u7684\u5167\u5bb9\u504f\u79fb\u91cf\u7d50\u5408\u4f7f\u7528\uff0c\u5f9e\u800c\u5be6\u73fe\u9801\u6578\u7684\u540c\u6b65\u66f4\u65b0\u3002<\/p>\n<h3>2. \u5982\u4f55\u81ea\u5b9a\u7fa9 UIPageControl \u7684\u6a23\u5f0f\uff1f<\/h3>\n<p>\u60a8\u53ef\u4ee5\u901a\u904e\u8a2d\u5b9a <strong>pageIndicatorTintColor<\/strong> \u548c <strong>currentPageIndicatorTintColor<\/strong> \u4f86\u81ea\u5b9a\u7fa9 UIPageControl \u7684\u984f\u8272\uff0c\u9084\u53ef\u4ee5\u4f7f\u7528\u81ea\u5b9a\u7fa9\u7684\u5716\u5f62\u4f86\u66ff\u4ee3\u5713\u9ede\u3002<\/p>\n<h3>3. \u4f7f\u7528 UIPageControl \u6642\uff0c\u6709\u4ec0\u9ebc\u9700\u8981\u6ce8\u610f\u7684\u6027\u80fd\u554f\u984c\u55ce\uff1f<\/h3>\n<p>\u5728\u5927\u91cf\u9801\u9762\u5167\u5bb9\u7684\u60c5\u6cc1\u4e0b\uff0c\u8acb\u78ba\u4fdd\u9069\u7576\u7ba1\u7406\u8996\u5716\u63a7\u5236\u5668\u7684\u751f\u547d\u9031\u671f\uff0c\u4ee5\u907f\u514d\u6027\u80fd\u4e0b\u964d\u3002<\/p>\n<p>&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u5c07\u4ecb\u7d39Swift\u4e2dUIPageControl\u7684\u9801\u6578\u63a7\u5236\u529f\u80fd\uff0c\u8b93\u958b\u767c\u8005\u53ef\u4ee5\u8f15\u9b06\u5730\u63a7\u5236\u9801\u9762\u7684\u9801\u6578\uff0c\u4e26\u66f4\u52a0\u4e86\u89e3UIPageControl\u7684\u4f7f\u7528\u65b9\u6cd5\u3002<\/p>\n","protected":false},"author":1,"featured_media":7163,"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-7164","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-UIPageControl-\ud83d\udcd6\u9801\u6578\u63a7\u5236\u5668\uff01_1675403782.9674518.webp","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1Ry","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7164","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=7164"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7164\/revisions"}],"predecessor-version":[{"id":13143,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7164\/revisions\/13143"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/7163"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=7164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=7164"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=7164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}