{"id":7390,"date":"2025-06-01T12:33:19","date_gmt":"2025-06-05T05:14:18","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=7390"},"modified":"2025-06-05T12:33:19","modified_gmt":"2025-06-05T05:14:18","slug":"https-badgameshow-com-steven-366","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/https-badgameshow-com-steven-366\/","title":{"rendered":"Swift UITabBarController \u5b8c\u6574\u958b\u767c\u6307\u5357\uff082025 \u6700\u65b0\u8a9e\u6cd5\u8207\u6700\u4f73\u5be6\u8e10\uff09"},"content":{"rendered":"<p>&#8220;`html<br \/>\n<meta name=\"keywords\" content=\"swift, UITabBarController, \u61c9\u7528\u7bc4\u4f8b, iOS \u958b\u767c, Swift \u6559\u5b78\"><\/p>\n<h2>\u4ecb\u7d39<\/h2>\n<p>Swift \u662f\u4e00\u7a2e\u65b0\u8208\u7684\u7a0b\u5f0f\u8a9e\u8a00\uff0c\u70ba iOS \u958b\u767c\u5e36\u4f86\u4e86\u7121\u9650\u7684\u53ef\u80fd\u6027\u3002\u672c\u6307\u5357\u5c07\u6df1\u5165\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528 Swift \u958b\u767c UITabBarController \u61c9\u7528\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u5feb\u901f\u5efa\u7acb\u5728 iOS \u88dd\u7f6e\u4e0a\u57f7\u884c\u7684\u61c9\u7528\u7a0b\u5f0f\u3002<\/p>\n<h2>\u4ec0\u9ebc\u662f UITabBarController\uff1f<\/h2>\n<p>UITabBarController \u662f iOS \u4e2d\u4e00\u500b\u91cd\u8981\u7684\u63a7\u5236\u5143\u4ef6\uff0c\u80fd\u5920\u8b93\u958b\u767c\u8005\u5c07\u591a\u500b ViewController \u7d44\u5408\u5728\u4e00\u8d77\uff0c\u4e26\u65b9\u4fbf\u4f7f\u7528\u8005\u5728\u4e0d\u540c\u7684 ViewController \u4e4b\u9593\u5feb\u901f\u5207\u63db\u3002\u9019\u7a2e\u8a2d\u8a08\u5927\u5927\u63d0\u9ad8\u4e86\u61c9\u7528\u7684\u53ef\u7528\u6027\u8207\u6613\u7528\u6027\u3002<\/p>\n<h2>\u958b\u767c\u6b65\u9a5f<\/h2>\n<h3>1. \u5efa\u7acb\u65b0\u7684 Xcode \u5c08\u6848<\/h3>\n<p>\u9996\u5148\uff0c\u6253\u958b Xcode \u4e26\u5efa\u7acb\u4e00\u500b\u65b0\u7684\u5c08\u6848\uff0c\u9078\u64c7 &#8220;App&#8221; \u6a21\u677f\uff0c\u7136\u5f8c\u5728 &#8220;Interface&#8221; \u90e8\u5206\u9078\u64c7 &#8220;Storyboard&#8221;\u3002<\/p>\n<h3>2. \u5efa\u7acb ViewControllers<\/h3>\n<p>\u5728\u5c08\u6848\u4e2d\u5efa\u7acb\u591a\u500b ViewController\uff0c\u6bcf\u4e00\u500b ViewController \u5c0d\u61c9\u5230\u4e00\u500b Tab\u3002\u5728\u6bcf\u500b ViewController \u4e2d\uff0c\u60a8\u53ef\u4ee5\u6dfb\u52a0\u4e0d\u540c\u7684 UI \u5143\u4ef6\u4f86\u986f\u793a\u5404\u81ea\u7684\u5167\u5bb9\u3002<\/p>\n<h3>3. \u8a2d\u5b9a UITabBarController<\/h3>\n<p>\u63a5\u4e0b\u4f86\uff0c\u5728 <code>SceneDelegate.swift<\/code> \u4e2d\u52a0\u5165\u4ee5\u4e0b\u7a0b\u5f0f\u78bc\uff0c\u4ee5\u5efa\u7acb UITabBarController \u4e26\u5c07\u591a\u500b ViewController \u52a0\u5165\u5176\u4e2d\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">let tabBarController = UITabBarController()\nlet firstViewController = FirstViewController()\nlet secondViewController = SecondViewController()\nlet thirdViewController = ThirdViewController()\n\ntabBarController.viewControllers = [firstViewController, secondViewController, thirdViewController]\n\nwindow?.rootViewController = tabBarController\n<\/code><\/pre>\n<h3>4. \u8a2d\u5b9a Tab \u6a19\u984c\u8207\u5716\u793a<\/h3>\n<p>\u5728\u6bcf\u500b ViewController \u4e2d\uff0c\u8a2d\u5b9a Tab \u7684\u6a19\u984c\u548c\u5716\u793a\uff0c\u4ee5\u4e0b\u662f\u7bc4\u4f8b\u7a0b\u5f0f\u78bc\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">firstViewController.tabBarItem = UITabBarItem(title: \"\u7b2c\u4e00\u500b\", image: UIImage(named: \"first\"), tag: 0)\nsecondViewController.tabBarItem = UITabBarItem(title: \"\u7b2c\u4e8c\u500b\", image: UIImage(named: \"second\"), tag: 1)\nthirdViewController.tabBarItem = UITabBarItem(title: \"\u7b2c\u4e09\u500b\", image: UIImage(named: \"third\"), tag: 2)\n<\/code><\/pre>\n<h2>\u932f\u8aa4\u6392\u9664<\/h2>\n<p>\u5728\u958b\u767c\u904e\u7a0b\u4e2d\uff0c\u53ef\u80fd\u6703\u9047\u5230\u4ee5\u4e0b\u5e38\u898b\u932f\u8aa4\uff1a<\/p>\n<ul>\n<li><strong>TabBar \u4e0d\u986f\u793a\uff1a<\/strong>\u78ba\u4fdd <code>tabBarController.viewControllers<\/code> \u4e2d\u5305\u542b\u7684 ViewController \u4e0d\u70ba\u7a7a\u3002<\/li>\n<li><strong>\u5716\u793a\u7121\u6cd5\u986f\u793a\uff1a<\/strong>\u6aa2\u67e5\u5716\u793a\u6a94\u540d\u662f\u5426\u6b63\u78ba\uff0c\u4e26\u78ba\u4fdd\u5716\u6a94\u5df2\u7d93\u6dfb\u52a0\u5230\u5c08\u6848\u4e2d\u3002<\/li>\n<\/ul>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>\u60a8\u53ef\u4ee5\u9032\u4e00\u6b65\u64f4\u5c55 UITabBarController \u7684\u529f\u80fd\uff0c\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528 <code>UINavigationController<\/code> \u5c07\u6bcf\u500b Tab \u5305\u88dd\u8d77\u4f86\uff0c\u4ee5\u63d0\u4f9b\u66f4\u6df1\u5c64\u7684\u5c0e\u822a\u9ad4\u9a57\u3002<\/li>\n<li>\u5728 Tab \u5207\u63db\u6642\u6dfb\u52a0\u904e\u6e21\u52d5\u756b\uff0c\u63d0\u5347\u4f7f\u7528\u8005\u9ad4\u9a57\u3002<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-UITabBarController-\u61c9\u7528\u7bc4\u4f8b-\ud83d\udd28_1675475159.342082.webp\" alt=\"Swift UITabBarController \u61c9\u7528\u7bc4\u4f8b \ud83d\udd28\" title=\"Swift UITabBarController \u61c9\u7528\u7a0b\u5f0f\u7bc4\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528 Swift \u958b\u767c\u591a Tab \u7684\u61c9\u7528\" width=\"1200\" height=\"628\"\/><\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<h3>1. UITabBarController \u53ef\u4ee5\u6709\u591a\u5c11\u500b Tab\uff1f<\/h3>\n<p>UITabBarController \u7406\u8ad6\u4e0a\u53ef\u4ee5\u652f\u6301\u4efb\u610f\u591a\u7684 Tab\uff0c\u4f46\u5be6\u969b\u4e0a\u5efa\u8b70\u4e0d\u8d85\u904e\u4e94\u500b\uff0c\u4ee5\u514d\u5f71\u97ff\u4f7f\u7528\u8005\u9ad4\u9a57\u3002<\/p>\n<h3>2. \u5982\u4f55\u81ea\u5b9a\u7fa9 TabBar \u7684\u5916\u89c0\uff1f<\/h3>\n<p>\u60a8\u53ef\u4ee5\u901a\u904e\u4fee\u6539 <code>UITabBar.appearance()<\/code> \u7684\u5c6c\u6027\u4f86\u81ea\u5b9a\u7fa9 TabBar \u7684\u984f\u8272\u3001\u5b57\u9ad4\u7b49\u5c6c\u6027\u3002<\/p>\n<h3>3. \u53ef\u4ee5\u5728 Tab \u4e4b\u9593\u50b3\u905e\u8cc7\u6599\u55ce\uff1f<\/h3>\n<p>\u53ef\u4ee5\uff01\u60a8\u53ef\u4ee5\u4f7f\u7528 delegate \u6216 closure \u7684\u65b9\u5f0f\u5728\u4e0d\u540c\u7684 ViewController \u4e4b\u9593\u50b3\u905e\u8cc7\u6599\u3002<\/p>\n<p>&#8220;`<br \/>\n&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981:\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528SwiftUITabBarController\u4f86\u5efa\u7acb\u61c9\u7528\u7a0b\u5f0f\uff0c\u4e26\u63a2\u8a0e\u5b83\u7684\u57fa\u672c\u529f\u80fd\uff0c\u4ee5\u53ca\u5982\u4f55\u5c07\u5b83\u8207\u5176\u4ed6\u6846\u67b6\u7d50\u5408\u4f7f\u7528\u3002\u6211\u5011\u5c07\u6df1\u5165\u63a2\u8a0eSwiftUITabBarController\u7684\u61c9\u7528\u7a0b\u5f0f\u7bc4\u4f8b\uff0c\u4ee5\u53ca\u5982\u4f55\u4f7f\u7528\u5b83\u4f86\u5efa\u7acb\u66f4\u591a\u529f\u80fd\u5f37\u5927\u7684\u61c9\u7528\u7a0b\u5f0f\u3002<\/p>\n","protected":false},"author":1,"featured_media":7388,"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-7390","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-UITabBarController-\u61c9\u7528\u7bc4\u4f8b-\ud83d\udd28_1675475159.342082.webp","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1Vc","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7390","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=7390"}],"version-history":[{"count":0,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7390\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/7388"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=7390"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=7390"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=7390"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}