{"id":1135,"date":"2020-10-14T14:33:02","date_gmt":"2020-10-14T06:33:02","guid":{"rendered":"http:\/\/123.57.164.21\/?p=1135"},"modified":"2020-10-14T14:33:13","modified_gmt":"2020-10-14T06:33:13","slug":"swiftui%e4%b8%ad%e6%9e%84%e5%bb%ba%e5%be%aa%e7%8e%af%e8%bf%9b%e5%ba%a6%e6%9d%a1","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=1135","title":{"rendered":"SwiftUI\u4e2d\u6784\u5efa\u5faa\u73af\u8fdb\u5ea6\u6761"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/123.57.164.21\/wp-content\/uploads\/2020\/10\/image-10.png\" alt=\"\" class=\"wp-image-1136\" width=\"514\" height=\"454\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2020\/10\/image-10.png 820w, https:\/\/92it.top\/wp-content\/uploads\/2020\/10\/image-10-300x265.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2020\/10\/image-10-768x678.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2020\/10\/image-10-230x203.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2020\/10\/image-10-350x309.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2020\/10\/image-10-480x424.png 480w\" sizes=\"(max-width: 514px) 100vw, 514px\" \/><\/figure><\/div>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\n\nimport SwiftUI\n\nstruct ContentView: View {\n    @State var progressValue: Float = 0.0\n    \n    var body: some View {\n        ZStack {\n            Color.yellow\n                .opacity(0.1)\n                .edgesIgnoringSafeArea(.all)\n            \n            VStack {\n                ProgressBar(progress: self.$progressValue)\n                    .frame(width: 150.0, height: 150.0)\n                    .padding(40.0)\n                \n                Button(action: {\n                    self.incrementProgress()\n                }) {\n                    HStack {\n                        Image(systemName: \"plus.rectangle.fill\")\n                        Text(\"Increment\")\n                    }\n                    .padding(15.0)\n                    .overlay(\n                        RoundedRectangle(cornerRadius: 15.0)\n                            .stroke(lineWidth: 2.0)\n                    )\n                }\n                \n                Spacer()\n            }\n        }\n    }\n    \n    func incrementProgress() {\n        let randomValue = Float([0.012, 0.022, 0.034, 0.016, 0.11].randomElement()!)\n        self.progressValue += randomValue\n    }\n}\nstruct ProgressBar: View {\n    @Binding var progress: Float\n    \n    var body: some View {\n        ZStack {\n            Circle()\n                .stroke(lineWidth: 20.0)\n                .opacity(0.3)\n                .foregroundColor(Color.red)\n            \n            Circle()\n                .trim(from: 0.0, to: CGFloat(min(self.progress, 1.0)))\n                .stroke(style: StrokeStyle(lineWidth: 20.0, lineCap: .round, lineJoin: .round))\n                .foregroundColor(Color.red)\n                .rotationEffect(Angle(degrees: 270.0))\n                .animation(.linear)\n\n            Text(String(format: \"%.0f %%\", min(self.progress, 1.0)*100.0))\n                .font(.largeTitle)\n                .bold()\n        }\n    }\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/1135"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1135"}],"version-history":[{"count":3,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/1135\/revisions"}],"predecessor-version":[{"id":1139,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/1135\/revisions\/1139"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1135"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}