{"id":577,"date":"2023-02-25T19:19:56","date_gmt":"2023-02-25T11:19:56","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=577"},"modified":"2023-04-29T20:32:29","modified_gmt":"2023-04-29T12:32:29","slug":"swift-ui-switch-button-uiswitch","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/25\/swift-ui-switch-button-uiswitch\/","title":{"rendered":"Swift UI &#8211; \u5f00\u5173\u6309\u94ae\uff08UISwitch\uff09"},"content":{"rendered":"<blockquote>\n<p>\u6ce8\uff1a\u4ee3\u7801\u5df2\u5347\u7ea7\u81f3Swift4<\/p>\n<\/blockquote>\n<p>\u521b\u5efaUISwitch\uff0c\u4ee5\u53ca\u76d1\u542c\u503c\u7684\u6539\u53d8<\/p>\n<p><!-- more --><\/p>\n<pre><code class=\"language-swift\">import UIKit\n\nclass ViewController: UIViewController {\n    var uiswitch:UISwitch!;\n\n    override func viewDidLoad() {\n        super.viewDidLoad()\n\n        uiswitch = UISwitch()\n        \/\/\u8bbe\u7f6e\u4f4d\u7f6e\uff08\u5f00\u5173\u5927\u5c0f\u65e0\u6cd5\u8bbe\u7f6e\uff09\n        uiswitch.center = CGPoint(x:100, y:50)\n        \/\/\u8bbe\u7f6e\u9ed8\u8ba4\u503c\n        uiswitch.isOn = true;\n        uiswitch.addTarget(self, action: #selector(switchDidChanged), for:.valueChanged)\n        self.view.addSubview(uiswitch);\n    }\n\n    func switchDidChanged() {\n        \/\/\u6253\u5370\u5f53\u524d\u503c\n        print(uiswitch.isOn)\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u6ce8\uff1a\u4ee3\u7801\u5df2\u5347\u7ea7\u81f3Swift4 \u521b\u5efaUISwitch\uff0c\u4ee5\u53ca\u76d1\u542c\u503c\u7684\u6539\u53d8 import UIKit class V [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[171],"tags":[],"class_list":["post-577","post","type-post","status-publish","format-standard","hentry","category-swift"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/577","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=577"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/577\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=577"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=577"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=577"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}