{"id":7100,"date":"2025-05-30T13:16:15","date_gmt":"2025-06-05T06:00:14","guid":{"rendered":"https:\/\/badgameshow.com\/steven\/?p=7100"},"modified":"2025-06-05T13:16:15","modified_gmt":"2025-06-05T06:00:14","slug":"https-badgameshow-com-steven-225","status":"publish","type":"post","link":"https:\/\/badgameshow.com\/steven\/swift\/https-badgameshow-com-steven-225\/","title":{"rendered":"Swift \u7a0b\u5f0f\u8a2d\u8a08\uff1a2025 \u6700\u65b0\u5f48\u51fa\u9078\u64c7\u6846\u6548\u679c\u6559\u5b78 \ud83d\udca5"},"content":{"rendered":"<p>&#8220;`html<br \/>\n<meta name=\"keywords\" content=\"swift, \u5f48\u51fa\u9078\u64c7\u6846\u6548\u679c, UIAlertController, iOS \u958b\u767c\"><\/p>\n<p>Swift \u662f\u4e00\u7a2e\u5ee3\u53d7\u6b61\u8fce\u7684\u7a0b\u5f0f\u8a9e\u8a00\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u5229\u7528\u5b83\u5feb\u901f\u5275\u5efa\u529f\u80fd\u5f37\u5927\u7684\u61c9\u7528\u7a0b\u5f0f\u3002\u5728 Swift \u4e2d\uff0c\u5f48\u51fa\u9078\u64c7\u6846\u6548\u679c\u662f\u63d0\u5347\u4f7f\u7528\u8005\u4e92\u52d5\u7684\u91cd\u8981\u5de5\u5177\uff0c\u80fd\u8b93\u4f7f\u7528\u8005\u5feb\u901f\u9078\u64c7\u6240\u9700\u7684\u9078\u9805\uff0c\u800c\u7121\u9700\u8f38\u5165\u6587\u5b57\u3002<\/p>\n<h2>\u5982\u4f55\u5728 Swift \u4e2d\u5be6\u73fe\u5f48\u51fa\u9078\u64c7\u6846\u6548\u679c\uff1f<\/h2>\n<p>\u5728 Swift \u4e2d\uff0c\u8981\u5be6\u73fe\u5f48\u51fa\u9078\u64c7\u6846\u6548\u679c\uff0c\u6211\u5011\u4f7f\u7528 <strong>UIAlertController<\/strong>\u3002\u4ee5\u4e0b\u662f\u5177\u9ad4\u6b65\u9a5f\uff1a<\/p>\n<ol>\n<li>\u5efa\u7acb\u4e00\u500b <strong>UIAlertController<\/strong> \u7269\u4ef6\uff0c\u4e26\u6307\u5b9a\u5176\u985e\u578b\u70ba <strong>UIAlertController.Style.actionSheet<\/strong>\u3002<\/li>\n<li>\u5b9a\u7fa9\u591a\u500b <strong>UIAlertAction<\/strong> \u7269\u4ef6\uff0c\u4e26\u6307\u5b9a\u5176\u985e\u578b\u70ba <strong>UIAlertAction.Style.default<\/strong>\uff0c\u4ee5\u5c07\u9078\u9805\u52a0\u5165\u5f48\u51fa\u9078\u64c7\u6846\u4e2d\u3002<\/li>\n<li>\u5c07 <strong>UIAlertAction<\/strong> \u7269\u4ef6\u52a0\u5165\u5230 <strong>UIAlertController<\/strong> \u4e2d\uff0c\u4e26\u986f\u793a\u51fa\u4f86\u3002<\/li>\n<\/ol>\n<p>\u4ee5\u4e0b\u662f\u5be6\u4f5c\u7bc4\u4f8b\uff1a<\/p>\n<pre><code class=\"language-swift line-numbers\">let alertController = UIAlertController(title: \"\u9078\u64c7\u4e00\u500b\u9078\u9805\", message: nil, preferredStyle: .actionSheet)\n\nlet option1 = UIAlertAction(title: \"\u9078\u98051\", style: .default) { (action) in\n    \/\/ \u57f7\u884c\u9078\u98051\u7684\u52d5\u4f5c\n}\n\nlet option2 = UIAlertAction(title: \"\u9078\u98052\", style: .default) { (action) in\n    \/\/ \u57f7\u884c\u9078\u98052\u7684\u52d5\u4f5c\n}\n\nalertController.addAction(option1)\nalertController.addAction(option2)\n\nself.present(alertController, animated: true, completion: nil)\n<\/code><\/pre>\n<p>\u900f\u904e\u4ee5\u4e0a\u7684\u7a0b\u5f0f\u78bc\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u5feb\u901f\u5728 Swift \u4e2d\u5be6\u73fe\u5f48\u51fa\u9078\u64c7\u6846\u6548\u679c\u3002<\/p>\n<h2>\u932f\u8aa4\u6392\u9664\u63d0\u793a<\/h2>\n<ul>\n<li>\u78ba\u4fdd\u5728\u4e3b\u57f7\u884c\u7dd2\u4e2d\u5448\u73fe UIAlertController\uff0c\u5426\u5247\u53ef\u80fd\u6703\u5c0e\u81f4\u61c9\u7528\u7a0b\u5f0f\u5d29\u6f70\u3002<\/li>\n<li>\u6aa2\u67e5\u4f60\u7684 ViewController \u662f\u5426\u6b63\u78ba\u986f\u793a\uff0c\u907f\u514d\u56e0\u70ba\u8996\u5716\u5c64\u7d1a\u554f\u984c\u5c0e\u81f4\u9078\u64c7\u6846\u7121\u6cd5\u986f\u793a\u3002<\/li>\n<\/ul>\n<h2>\u5ef6\u4f38\u61c9\u7528<\/h2>\n<p>\u5f48\u51fa\u9078\u64c7\u6846\u53ef\u4ee5\u7528\u65bc\u8a31\u591a\u60c5\u5883\uff0c\u4f8b\u5982\u9078\u64c7\u984f\u8272\u3001\u8a2d\u5b9a\u9078\u9805\u6216\u78ba\u8a8d\u522a\u9664\u64cd\u4f5c\u7b49\u3002\u958b\u767c\u8005\u53ef\u4ee5\u6839\u64da\u9700\u6c42\u81ea\u5b9a\u7fa9\u9078\u9805\u548c\u884c\u70ba\uff0c\u9032\u4e00\u6b65\u63d0\u5347\u4f7f\u7528\u8005\u9ad4\u9a57\u3002<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/badgameshow.com\/steven\/wp-content\/uploads\/2023\/02\/Swift-\u5f48\u51fa\u9078\u64c7\u6846\u6548\u679c-\ud83d\udca5_1675402471.5323079.webp\" alt=\"Swift \u5f48\u51fa\u9078\u64c7\u6846\u6548\u679c \ud83d\udca5\" title=\"Swift\u5f48\u51fa\u9078\u64c7\u6846, Swift\u9078\u64c7\u6846\u6548\u679c, Swift methods()\u51fd\u6578, Swift\u61c9\u7528\u7a0b\u5f0f\u529f\u80fd, Swift\u5f48\u51fa\u9078\u64c7\u6846\u6548\u679c\" width=\"1200\" height=\"628\"\/><\/p>\n<h2>Q&#038;A\uff08\u5e38\u898b\u554f\u984c\u89e3\u7b54\uff09<\/h2>\n<h3>1. \u5982\u4f55\u81ea\u5b9a\u7fa9\u5f48\u51fa\u9078\u64c7\u6846\u7684\u6309\u9215\u984f\u8272\uff1f<\/h3>\n<p>\u53ef\u4ee5\u901a\u904e\u8a2d\u7f6e <strong>UIAlertAction<\/strong> \u7684 <strong>setValue(_:forKey:)<\/strong> \u65b9\u6cd5\u4f86\u81ea\u5b9a\u7fa9\u6309\u9215\u984f\u8272\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>option1.setValue(UIColor.red, forKey: \"titleTextColor\")<\/code><\/pre>\n<h3>2. \u53ef\u4ee5\u5728\u5f48\u51fa\u9078\u64c7\u6846\u4e2d\u6dfb\u52a0\u5716\u7247\u55ce\uff1f<\/h3>\n<p>\u96d6\u7136 <strong>UIAlertController<\/strong> \u672c\u8eab\u4e0d\u652f\u6301\u76f4\u63a5\u6dfb\u52a0\u5716\u7247\uff0c\u4f46\u4f60\u53ef\u4ee5\u4f7f\u7528\u81ea\u5b9a\u7fa9\u7684\u8996\u5716\u4f86\u5be6\u73fe\u76f8\u4f3c\u7684\u6548\u679c\u3002<\/p>\n<h3>3. \u5982\u4f55\u8655\u7406\u9078\u64c7\u6846\u7684\u53d6\u6d88\u4e8b\u4ef6\uff1f<\/h3>\n<p>\u53ef\u4ee5\u4f7f\u7528 <strong>UIAlertAction<\/strong> \u4f86\u6dfb\u52a0\u4e00\u500b\u53d6\u6d88\u9078\u9805\uff0c\u4e26\u5728\u76f8\u61c9\u7684\u9589\u5305\u4e2d\u8655\u7406\u53d6\u6d88\u4e8b\u4ef6\u3002<\/p>\n<p>&#8220;`<br \/>\n&#8212;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6458\u8981:\u5b78\u7fd2\u5982\u4f55\u5728Swift\u4e2d\u4f7f\u7528\u5f48\u51fa\u9078\u64c7\u6846\u6548\u679c\uff0c\u8b93\u4f60\u7684\u61c9\u7528\u7a0b\u5f0f\u66f4\u52a0\u6709\u8da3\uff0c\u66f4\u5bb9\u6613\u4f7f\u7528\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u4f7f\u7528Swift\u4e2d\u7684methods()\u51fd\u6578\uff0c\u4ee5\u53ca\u5982\u4f55\u5229\u7528\u5f48\u51fa\u9078\u64c7\u6846\u6548\u679c\u4f86\u589e\u5f37\u61c9\u7528\u7a0b\u5f0f\u7684\u529f\u80fd\u3002<\/p>\n","protected":false},"author":1,"featured_media":7099,"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-7100","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-\u5f48\u51fa\u9078\u64c7\u6846\u6548\u679c-\ud83d\udca5_1675402471.5323079.webp","jetpack-related-posts":[],"jetpack_shortlink":"https:\/\/wp.me\/pcFK27-1Qw","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7100","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=7100"}],"version-history":[{"count":1,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7100\/revisions"}],"predecessor-version":[{"id":13193,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/posts\/7100\/revisions\/13193"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media\/7099"}],"wp:attachment":[{"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/media?parent=7100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/categories?post=7100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/badgameshow.com\/steven\/wp-json\/wp\/v2\/tags?post=7100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}