├── .gitignore ├── Hello-Info.plist ├── Hello.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ └── xcuserdata │ │ └── a1.xcuserdatad │ │ ├── IDEFindNavigatorScopes.plist │ │ └── UserInterfaceState.xcuserstate ├── xcshareddata │ └── xcschemes │ │ └── HelloSwift.xcscheme └── xcuserdata │ ├── a1.xcuserdatad │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ │ └── xcschememanagement.plist │ └── hx.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ └── xcschememanagement.plist ├── HelloSwift.entitlements ├── HelloSwiftRelease.entitlements ├── README.md ├── docs ├── @ViewBuilder.md ├── List_Searchable.md ├── SwifUI视图.md ├── static │ ├── overview.gif │ └── qrcode.png └── textFieldStyle.md └── hello ├── API ├── api_Contacts.swift ├── api_CoreLocation.swift ├── api_CoreLocationUI.swift ├── api_Notifications.swift ├── api_PHPicker.swift ├── api_PhotosPicker.swift ├── api_RecordSound.swift ├── api_SQLite3.swift ├── api_URLSession.swift ├── api_URLSession_Post.swift ├── api_UserDefaults.swift ├── api_WebView.swift ├── api_audio.swift ├── api_camera_photo.swift ├── api_clipboard.swift ├── api_getSystemInfo.swift ├── api_network.swift ├── api_openURL.swift ├── api_saveImage.swift ├── api_share.swift └── api_video.swift ├── Articles ├── ArticleList.swift ├── SwiftUIView.swift ├── TutorialFirst.swift ├── TutorialFramework.swift ├── TutorialSwift.swift ├── TutorialSwiftSimple.swift ├── TutorialSwiftUI.swift └── firstSight │ ├── TutorialCreateProject.swift │ ├── TutorialDeveloperAccount.swift │ └── TutorialIntroduction.swift ├── Assets.xcassets ├── AccentColor.colorset │ └── Contents.json ├── AppIcon.appiconset │ ├── 1024x1024.png │ ├── 120x120 1.png │ ├── 120x120.png │ ├── 152x152.png │ ├── 167x167.png │ ├── 180x180.png │ ├── 20x20.png │ ├── 29x29.png │ ├── 40x40 1.png │ ├── 40x40 2.png │ ├── 40x40.png │ ├── 58x58 1.png │ ├── 58x58.png │ ├── 60x60.png │ ├── 76x76.png │ ├── 80x80 1.png │ ├── 80x80.png │ ├── 87x87.png │ └── Contents.json ├── Avatars │ ├── Avatar Default.imageset │ │ ├── Avatar Default.jpg │ │ └── Contents.json │ └── Contents.json ├── Backgrounds │ ├── Background1.imageset │ │ ├── Background 1.jpg │ │ └── Contents.json │ ├── Background10.imageset │ │ ├── Background 10.jpg │ │ └── Contents.json │ ├── Background2.imageset │ │ ├── Background 2.jpg │ │ └── Contents.json │ ├── Background3.imageset │ │ ├── Background 3.jpg │ │ └── Contents.json │ ├── Background4.imageset │ │ ├── Background 4.jpg │ │ └── Contents.json │ ├── Background5.imageset │ │ ├── Background 5.jpg │ │ └── Contents.json │ ├── Background6.imageset │ │ ├── Background 6.jpg │ │ └── Contents.json │ ├── Background7.imageset │ │ ├── Background 7.jpg │ │ └── Contents.json │ ├── Background8.imageset │ │ ├── Background 8.jpg │ │ └── Contents.json │ ├── Background9.imageset │ │ ├── Background 9.jpg │ │ └── Contents.json │ ├── Blob1.imageset │ │ ├── Blob 1 Dark.pdf │ │ ├── Blob 1.pdf │ │ └── Contents.json │ ├── Contents.json │ ├── Illustration.imageset │ │ ├── Contents.json │ │ └── Illustration 5.png │ ├── Waves1.imageset │ │ ├── Contents.json │ │ ├── Waves 1 Dark.pdf │ │ └── Waves 1.pdf │ └── Waves2.imageset │ │ ├── Contents.json │ │ ├── Waves 2 Dark.pdf │ │ └── Waves 2.pdf ├── Colors │ ├── Background.colorset │ │ └── Contents.json │ ├── Contents.json │ └── Shadow.colorset │ │ └── Contents.json ├── Contents.json ├── Documents │ ├── Contents.json │ ├── create_project_1.imageset │ │ ├── Contents.json │ │ └── create_project_1.jpg │ ├── create_project_2.imageset │ │ ├── Contents.json │ │ └── create_project_2.jpg │ ├── create_project_3.imageset │ │ ├── Contents.json │ │ └── create_project_3.jpg │ ├── create_project_4.imageset │ │ ├── Contents.json │ │ └── create_project_4.jpg │ └── hello.imageset │ │ ├── Contents.json │ │ └── hello.jpg ├── Home │ ├── Contents.json │ ├── icon_lang.imageset │ │ ├── 180x180 1.png │ │ ├── 180x180.png │ │ ├── 80x80.png │ │ └── Contents.json │ ├── icon_sdk.imageset │ │ ├── Contents.json │ │ ├── sdk 1.svg │ │ ├── sdk 2.svg │ │ └── sdk.svg │ ├── icon_swift.imageset │ │ ├── Contents.json │ │ ├── icon_swift 1.png │ │ ├── icon_swift 2.png │ │ └── icon_swift.png │ └── icon_swiftui.imageset │ │ ├── Contents.json │ │ ├── icon_swiftui 1.png │ │ ├── icon_swiftui 2.png │ │ └── icon_swiftui.png ├── example │ ├── Contents.json │ └── car.imageset │ │ ├── Contents.json │ │ ├── car 1.png │ │ ├── car 2.png │ │ └── car.png └── icon │ ├── Contents.json │ ├── code.imageset │ ├── Contents.json │ ├── code.png │ ├── code128.png │ └── code256.png │ ├── search.imageset │ ├── Contents.json │ ├── search-1.png │ ├── search-2.png │ └── search.png │ ├── shake.imageset │ ├── Contents.json │ ├── shake_128.png │ ├── shake_256.png │ └── shake_512.png │ └── start.imageset │ ├── Contents.json │ └── start.jpeg ├── Common ├── Show_SwiftUI_Docs.swift ├── ToastView.swift ├── common.swift ├── loadLocalHtml.swift ├── loadMarkDownInHtml.swift ├── loadOpenUrl.swift ├── loadSwiftProgrammingLanguage.swift ├── navBarViewCodeAndDocs.swift ├── navigationBarColorForALL.swift ├── readMarkDownFile.swift ├── styles.swift ├── urlRequest1.swift ├── urlRequest2.swift └── viewExtension.swift ├── Components ├── Animation │ ├── Effect.swift │ ├── Mask.swift │ ├── Shadow.swift │ ├── TapDelay.swift │ ├── Timing.swift │ ├── Transitions.swift │ └── a_withAnimation.swift ├── Gesture │ ├── v_DragGesture.swift │ ├── v_MagnificationGesture.swift │ ├── v_RotationGesture.swift │ ├── v_SpatialTapGesture.swift │ ├── v_gesture_LongPressGesture.swift │ ├── v_onLongPressGesture.swift │ └── v_onTapGesture.swift ├── Image │ ├── v_image_AsyncImage.swift │ ├── v_image_SF.swift │ ├── v_image_URLSession.swift │ └── v_image_local.swift ├── Other │ ├── v_blur.swift │ ├── v_fileExporter.swift │ └── v_statusBar.swift ├── Picker │ ├── v_ColorPicker.swift │ ├── v_DatePicker.swift │ ├── v_MultiPicker.swift │ ├── v_pickerStyle_default.swift │ ├── v_pickerStyle_inline.swift │ ├── v_pickerStyle_menu.swift │ ├── v_pickerStyle_segmented.swift │ └── v_pickerStyle_wheel.swift ├── Shapes │ ├── v_Capsule.swift │ ├── v_CapsuleGroup.swift │ ├── v_Circle.swift │ ├── v_CircleProgressBar.swift │ ├── v_Ellipse.swift │ ├── v_Path.swift │ ├── v_Rectangle.swift │ └── v_RoundedRectangle.swift ├── TextField │ ├── InputAccentColor.swift │ ├── InputAutoFocus.swift │ ├── InputBorder.swift │ ├── InputCloseKeyBoard.swift │ ├── InputFormatter.swift │ ├── InputKeyboardButtons.swift │ ├── InputKeyboardType.swift │ ├── InputOn.swift │ ├── InputSecureField.swift │ ├── InputStyle.swift │ └── InputWithIcon.swift ├── chart_BarMark.swift ├── chart_LineMark.swift ├── chart_PointMark.swift ├── toolbar │ ├── v_toolbar_automatic.swift │ ├── v_toolbar_bottomBar.swift │ ├── v_toolbar_cancellationAction.swift │ ├── v_toolbar_destructiveAction.swift │ ├── v_toolbar_keyboard.swift │ ├── v_toolbar_navigation.swift │ ├── v_toolbar_navigationBarLeading.swift │ ├── v_toolbar_navigationBarTrailing.swift │ ├── v_toolbar_primaryAction.swift │ ├── v_toolbar_principal.swift │ ├── v_toolbar_secondaryAction.swift │ └── v_toolbar_status.swift ├── v_ActionSheet.swift ├── v_Alert.swift ├── v_Button.swift ├── v_Canvas.swift ├── v_Colors.swift ├── v_DisclosureGroup.swift ├── v_Divider.swift ├── v_Form.swift ├── v_Gauge.swift ├── v_Gesture.swift ├── v_Gradient.swift ├── v_Grid.swift ├── v_Group.swift ├── v_GroupBox.swift ├── v_Image.swift ├── v_Label.swift ├── v_LabeledContent.swift ├── v_Layout.swift ├── v_Link.swift ├── v_List.swift ├── v_Maps.swift ├── v_Menu.swift ├── v_Navigation.swift ├── v_NavigationSetting.swift ├── v_NavigationStack.swift ├── v_NavigationView.swift ├── v_OutlineGroup.swift ├── v_PasteButton.swift ├── v_Picker.swift ├── v_Popover.swift ├── v_ProgressView.swift ├── v_ScrollView.swift ├── v_ScrollViewReader.swift ├── v_ScrollView_horizontal.swift ├── v_ScrollView_vertical.swift ├── v_Sheet.swift ├── v_Slider.swift ├── v_Spacer.swift ├── v_Stepper.swift ├── v_Tab.swift ├── v_Table.swift ├── v_Text.swift ├── v_TextEditor.swift ├── v_TextField.swift ├── v_TimelineView.swift ├── v_Toggle.swift ├── v_confirmationDialog.swift ├── v_contextMenu.swift ├── v_extensionView.swift ├── v_fullScreenCover.swift ├── v_ignoresSafeArea.swift ├── v_modifier.swift ├── v_navigationBarItems.swift ├── v_offset.swift ├── v_position.swift ├── v_safeAreaInset.swift ├── v_section.swift ├── v_shape.swift ├── v_swipeActions.swift └── v_toolbar.swift ├── Config ├── ConfigApi.swift ├── ConfigFramework.swift ├── ConfigSwift.swift ├── ConfigSwiftUI.swift └── ConfigSwiftUI_Desc.swift ├── Launch Screen.storyboard ├── MainSceneDelegate.swift ├── MainView.swift ├── Preview Content └── Preview Assets.xcassets │ └── Contents.json ├── ReleaseNote.swift ├── Resouces.bundle ├── App │ ├── firstSight │ │ ├── CreateProject.html │ │ ├── XcodeInstall.html │ │ ├── introduce.md │ │ └── static │ │ │ ├── create_project_1.jpg │ │ │ ├── create_project_2.jpg │ │ │ ├── create_project_3.jpg │ │ │ ├── create_project_4.jpg │ │ │ ├── xcode_details.jpg │ │ │ └── xcode_icon.png │ └── static │ │ ├── github.min.css │ │ ├── highlight.min.js │ │ ├── marked.min.js │ │ └── swift.min.js ├── Root.plist ├── en.lproj │ └── Root.strings ├── markdown.css └── media │ └── example_audio.m4a ├── RootView.swift ├── SearchBar.swift ├── ViewController.swift ├── Views ├── API.swift ├── About.swift ├── Examples.swift ├── GlobalSearch.swift ├── Home.swift ├── NavigationBar.swift └── SwiftUIComponentsView.swift └── example ├── LifeCycle.swift ├── p_ScrollWithRotate3DEffect.swift ├── p_Shake.swift ├── p_contentShape.swift ├── p_environment.swift ├── p_markdownWithAttributedString.swift ├── p_navigationBar.swift ├── p_tabbar.swift ├── p_tabview.swift ├── p_tmp.swift └── p_toolbar.swift /.gitignore: -------------------------------------------------------------------------------- 1 | # Mac 2 | .DS_Store 3 | **/.DS_Store 4 | 5 | # vim/vi 6 | *.swp 7 | convert_md_html.py 8 | 9 | hello/Resouces.bundle/App/API/ 10 | hello/Resouces.bundle/App/SwiftUI/ 11 | -------------------------------------------------------------------------------- /Hello-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleGetInfoString 6 | 7 | CFBundleLocalizations 8 | 9 | en 10 | zh 11 | zh_TW 12 | 13 | NSAppTransportSecurity 14 | 15 | NSAllowsArbitraryLoads 16 | 17 | NSAllowsArbitraryLoadsForMedia 18 | 19 | NSAllowsArbitraryLoadsInWebContent 20 | 21 | 22 | NSUserNotificationsUsageDescription 23 | 该应用需要使用通知,以便为你演示相关功能 24 | UIApplicationShortcutItems 25 | 26 | 27 | UIApplicationShortcutItemIconType 28 | UIApplicationShortcutIconTypeSearch 29 | UIApplicationShortcutItemTitle 30 | 搜索 31 | UIApplicationShortcutItemType 32 | Search 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /Hello.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Hello.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Hello.xcodeproj/project.xcworkspace/xcuserdata/a1.xcuserdatad/IDEFindNavigatorScopes.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Hello.xcodeproj/project.xcworkspace/xcuserdata/a1.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/Hello.xcodeproj/project.xcworkspace/xcuserdata/a1.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Hello.xcodeproj/xcuserdata/a1.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 9 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Hello.xcodeproj/xcuserdata/a1.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | HelloSwift.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | format.xcscheme_^#shared#^_ 13 | 14 | orderHint 15 | 0 16 | 17 | simple-widgetExtension copy.xcscheme_^#shared#^_ 18 | 19 | orderHint 20 | 4 21 | 22 | simple-widgetExtension.xcscheme_^#shared#^_ 23 | 24 | orderHint 25 | 2 26 | 27 | testExtension.xcscheme_^#shared#^_ 28 | 29 | orderHint 30 | 1 31 | 32 | widgetExtension.xcscheme_^#shared#^_ 33 | 34 | orderHint 35 | 3 36 | 37 | 38 | SuppressBuildableAutocreation 39 | 40 | E5C85280288A51B500BBB795 41 | 42 | primary 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /Hello.xcodeproj/xcuserdata/hx.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | HelloSwift.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | format.xcscheme_^#shared#^_ 13 | 14 | orderHint 15 | 0 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /HelloSwift.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /HelloSwiftRelease.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /docs/List_Searchable.md: -------------------------------------------------------------------------------- 1 | # List Searchable 2 | 3 | ### 用法 4 | 5 | ``` 6 | List() {} 7 | .searchable(text: $searchKeyword, placement: SearchFieldPlacement.automatic, prompt: "搜索") 8 | ``` 9 | 10 | ### SearchFieldPlacement 11 | 12 | > 定义搜索框在视图中的位置 13 | 14 | 在用户滚动时始终可见搜索框 15 | 16 | ```swift 17 | .searchable(text: $searchKeyword, placement: SearchFieldPlacement.navigationBarDrawer(displayMode: .always)) 18 | ``` 19 | 20 | 将搜索框置于导航栏中 21 | 22 | ```swift 23 | .searchable(text: $searchFood, placement: SearchFieldPlacement.toolbar) 24 | ``` -------------------------------------------------------------------------------- /docs/SwifUI视图.md: -------------------------------------------------------------------------------- 1 | ## SwiftUI 如何处理视图 2 | 3 | > 本文来源:https://www.fatbobman.com/ 4 | 5 | SwiftUI 从加载视图、响应状态到屏幕绘制大概经历如下过程: 6 | 7 | - 从根视图开始按视图层级结构沿特定分支(依据初始状态)逐个实例化视图,直到满足当前全部的显示所需 8 | - 上述实例化后的视图值(结构值,非 body 值)将被保存在 SwiftUI 的托管数据池中 9 | - 根据视图的依赖信息在 AttributeGraph 数据池中创建与当前显示的视图树对应的依赖图,并监控依赖的变化 10 | - 依据 SwiftUI 数据池中视图值的 body 属性或视图类型的特定类型方法(非公开)进行布局和渲染 11 | - 当用户或系统的某些行为导致依赖数据发生变化后,SwiftUI 将根据依赖图定位到需要重新评估的视图 12 | - 以需重新评估的视图为根,按视图层级结构依当前状态逐个实例化视图类型(到满足全部显示所需为止) 13 | - 将已不再需要参与布局和渲染的视图的值从 SwiftUI 数据池中移除,并在数据池中添加上新增的视图值 14 | - 对于仍需显示但视图值发生变化的视图,使用新的视图值替换原有视图值 15 | - 重组依赖图并绘制新增及发生变化的视图 16 | - 周而复始、循环往复 17 | -------------------------------------------------------------------------------- /docs/static/overview.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/docs/static/overview.gif -------------------------------------------------------------------------------- /docs/static/qrcode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/docs/static/qrcode.png -------------------------------------------------------------------------------- /docs/textFieldStyle.md: -------------------------------------------------------------------------------- 1 | # 自定义输入框样式 2 | 3 | iOS上,textFieldStyle, 有3种样式: .automation、.plain、.roundedBorder。 4 | 5 | 当然,您也可以自定义Style。遵行TextFieldStyle协议,重写_body方法即可 6 | 7 | ```swift 8 | struct InputCustomStyle: TextFieldStyle { 9 | func _body(configuration: TextField) -> some View { 10 | HStack { 11 | Text("") 12 | .padding(.horizontal, 2) 13 | configuration 14 | .frame(height: 40) 15 | }.background(.white) 16 | } 17 | } 18 | ``` -------------------------------------------------------------------------------- /hello/API/api_WebView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // api_WebView.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 8/21/22. 6 | // 7 | 8 | import SwiftUI 9 | import WebKit 10 | 11 | fileprivate struct WebView: UIViewRepresentable { 12 | var url: URL 13 | 14 | func makeUIView(context: Context) -> WKWebView { 15 | return WKWebView() 16 | } 17 | 18 | func updateUIView(_ uiView: WKWebView, context: Context) { 19 | let request = URLRequest(url: url) 20 | uiView.load(request) 21 | uiView.allowsBackForwardNavigationGestures = true 22 | } 23 | } 24 | 25 | struct api_WebView: View { 26 | @State var urlSite:String = "https://www.baidu.com" 27 | 28 | var body: some View { 29 | WebView(url: URL(string: self.urlSite)!) 30 | .edgesIgnoringSafeArea([.bottom]) 31 | .navigationTitle("WebView") 32 | .navigationBarTitleDisplayMode(.inline) 33 | .modifier(navBarViewCodeAndDocs(pageType: "API",pageID: "WebView")) 34 | } 35 | } 36 | 37 | struct api_WebView_Previews: PreviewProvider { 38 | static var previews: some View { 39 | api_WebView() 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /hello/API/api_clipboard.swift: -------------------------------------------------------------------------------- 1 | // 2 | // api_clipboard.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 8/5/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct api_clipboard: View { 11 | @State var inputText:String = "" 12 | @FocusState var isFocused: Bool 13 | 14 | var body: some View { 15 | Form { 16 | Section(header: Text("剪切板功能,主要用到了 UIPasteboard.general").textCase(.none)) { 17 | TextEditor(text: $inputText) 18 | .frame(height: 200) 19 | .cornerRadius(10) 20 | .focused($isFocused) 21 | .onAppear(){ 22 | DispatchQueue.main.asyncAfter(deadline: .now() + 0.5){ 23 | self.isFocused = true 24 | } 25 | } 26 | } 27 | 28 | Button("将输入框内容写入剪贴板", action: { 29 | UIPasteboard.general.string = self.inputText 30 | }) 31 | 32 | Button("读取剪切板到输入框", action: { 33 | if UIPasteboard.general.hasStrings { 34 | self.inputText = UIPasteboard.general.string ?? "" 35 | } 36 | }) 37 | } 38 | .navigationTitle("clipboard") 39 | .modifier(navBarViewCodeAndDocs(pageType: "API",pageID: "clipboard")) 40 | } 41 | } 42 | 43 | struct api_clipboard_Previews: PreviewProvider { 44 | static var previews: some View { 45 | api_clipboard() 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /hello/API/api_network.swift: -------------------------------------------------------------------------------- 1 | // 2 | // api_network.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 8/23/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct api_network: View { 11 | @EnvironmentObject var network: NetworkMonitor 12 | 13 | var body: some View { 14 | VStack(spacing: 40) { 15 | Text(network.isActive ? "网络状态:在线" : "网络状态:无网络或App无网络访问权限") 16 | 17 | Text("网络类型:") + Text(verbatim: "\(network.connectionType)") 18 | .font(.title) 19 | 20 | Text("试试切换蜂窝网络、WIFI、或关闭网络,此处会自动刷新") 21 | .font(.caption) 22 | .foregroundColor(.gray) 23 | } 24 | .navigationTitle("获取网络状态") 25 | .navigationBarTitleDisplayMode(.inline) 26 | .modifier(navBarViewCodeAndDocs(pageType: "API",pageID: "NetMonitor")) 27 | } 28 | } 29 | 30 | struct api_network_Previews: PreviewProvider { 31 | static var previews: some View { 32 | api_network() 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /hello/API/api_share.swift: -------------------------------------------------------------------------------- 1 | // 2 | // api_share.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 8/2/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct api_share: View { 11 | var body: some View { 12 | VStack { 13 | Button(action: { 14 | shareButton() 15 | }, label: { 16 | Label("系统分享", systemImage: "square.and.arrow.up") 17 | .frame(width: 200) 18 | }) 19 | .tint(.purple) 20 | .controlSize(.large) 21 | .buttonStyle(.borderedProminent) 22 | 23 | Text("说明:本页面功能主要用到了: UIApplication.shared.windows ") 24 | .font(.caption) 25 | .foregroundColor(.gray) 26 | .frame(height: 80) 27 | } 28 | .padding() 29 | .navigationTitle("Shared - 系统分享") 30 | .navigationBarTitleDisplayMode(.inline) 31 | .modifier(navBarViewCodeAndDocs(pageType: "API",pageID: "Shared")) 32 | } 33 | 34 | func shareButton() { 35 | let url = URL(string: "itms-apps://itunes.apple.com/cn/app/id1643821819") 36 | let activityController = UIActivityViewController( 37 | activityItems: [url!], 38 | applicationActivities: nil 39 | ) 40 | 41 | UIApplication.shared.windows.first?.rootViewController!.present( 42 | activityController, 43 | animated: true, 44 | completion: nil 45 | ) 46 | } 47 | } 48 | 49 | struct api_share_Previews: PreviewProvider { 50 | static var previews: some View { 51 | api_share() 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /hello/Articles/SwiftUIView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SwiftUIView.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/18/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct SwiftUIView: View { 11 | var body: some View { 12 | Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/) 13 | } 14 | } 15 | 16 | struct SwiftUIView_Previews: PreviewProvider { 17 | static var previews: some View { 18 | SwiftUIView() 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /hello/Articles/TutorialFramework.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TutorialFramework.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/10/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct TutorialFramework: View { 11 | var body: some View { 12 | VStack(alignment: .leading) { 13 | Group { 14 | Text("App内,底部选项卡 “API”页面,演示了部分iOS系统API,如网络请求、选择相册照片、定位、分享等。") 15 | Text("下面罗列一些常用的iOS系统框架列表") 16 | } 17 | .padding() 18 | 19 | List { 20 | ForEach(FrameworkList, id: \.id) { sea in 21 | Section(header: Text(sea.name).font(.headline).foregroundColor(.black)) { 22 | ForEach(sea.seas) { item in 23 | HStack { 24 | Text(item.name) 25 | Text(item.available) 26 | .font(.footnote) 27 | .foregroundColor(.secondary) 28 | } 29 | } 30 | } 31 | } 32 | } 33 | .listStyle(.plain) 34 | } 35 | 36 | .frame(maxWidth: .infinity, maxHeight: .infinity) 37 | .background(Color.init(uiColor: UIColor(hexString: "#F2F6FE"))) 38 | .navigationTitle("Framework") 39 | .navigationBarTitleDisplayMode(.inline) 40 | } 41 | } 42 | 43 | struct TutorialFramework_Previews: PreviewProvider { 44 | static var previews: some View { 45 | TutorialFramework() 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /hello/Articles/TutorialSwiftSimple.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TutorialSwiftSimple.swift 3 | // Hello 4 | // 5 | // Created by 1 on 10/15/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct TutorialSwiftSimple: View { 11 | var body: some View { 12 | VStack(alignment: .center, spacing: 50) { 13 | Text("由于网络上很多Swift中文教程,本页面不再显示,可以在App【极简开发】中查看。") 14 | 15 | Button(action: { 16 | gotoStore() 17 | }, label: { 18 | Label("下载App 极简开发", systemImage: "arrow.down.circle") 19 | .padding() 20 | .foregroundColor(.white) 21 | .background( 22 | .pink, 23 | in: RoundedRectangle(cornerRadius: 8) 24 | ) 25 | }) 26 | } 27 | .padding() 28 | } 29 | 30 | func gotoStore() { 31 | let url = URL(string: "itms-apps://itunes.apple.com/cn/app/id1643821819")! 32 | 33 | if !UIApplication.shared.canOpenURL(url) { 34 | return 35 | } 36 | 37 | UIApplication.shared.open(url) { (success) in 38 | print("跳转状态: \(success)") 39 | } 40 | } 41 | } 42 | 43 | struct TutorialSwiftSimple_Previews: PreviewProvider { 44 | static var previews: some View { 45 | TutorialSwiftSimple() 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /hello/Articles/firstSight/TutorialIntroduction.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TutorialIntroduction.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/10/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | fileprivate let primer = """ 11 | Swift语言,让iOS开发门槛降低,只要您有点计算机基础,普通用户也将是开发者。 12 | 13 | """ 14 | 15 | fileprivate let ready = """ 16 | * 有一定的计算机基础。 17 | 18 | * 有一台Mac电脑 19 | 20 | * 有一台iPone或iPad设备 21 | 22 | * 注册一个Apple ID 23 | 24 | * 学习热情。保持热情更容易成功。 25 | """ 26 | 27 | struct TutorialIntroduction: View { 28 | 29 | var body: some View { 30 | ScrollView { 31 | VStack(alignment: .leading, spacing: 20) { 32 | Text(primer) 33 | 34 | Text("在学习Swift之前,您需要准备") 35 | .font(.headline) 36 | Divider() 37 | Text(ready) 38 | } 39 | .lineSpacing(6.0) 40 | .padding() 41 | } 42 | .navigationTitle("初见") 43 | .navigationBarTitleDisplayMode(.inline) 44 | } 45 | } 46 | 47 | struct TutorialIntroduction_Previews: PreviewProvider { 48 | static var previews: some View { 49 | TutorialIntroduction() 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "color" : { 5 | "color-space" : "srgb", 6 | "components" : { 7 | "alpha" : "1.000", 8 | "blue" : "0xD5", 9 | "green" : "0x34", 10 | "red" : "0x62" 11 | } 12 | }, 13 | "idiom" : "universal" 14 | }, 15 | { 16 | "appearances" : [ 17 | { 18 | "appearance" : "luminosity", 19 | "value" : "dark" 20 | } 21 | ], 22 | "color" : { 23 | "color-space" : "srgb", 24 | "components" : { 25 | "alpha" : "1.000", 26 | "blue" : "0xFF", 27 | "green" : "0x9E", 28 | "red" : "0x5E" 29 | } 30 | }, 31 | "idiom" : "universal" 32 | } 33 | ], 34 | "info" : { 35 | "author" : "xcode", 36 | "version" : 1 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/AppIcon.appiconset/1024x1024.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/AppIcon.appiconset/1024x1024.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/AppIcon.appiconset/120x120 1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/AppIcon.appiconset/120x120 1.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/AppIcon.appiconset/120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/AppIcon.appiconset/120x120.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/AppIcon.appiconset/152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/AppIcon.appiconset/152x152.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/AppIcon.appiconset/167x167.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/AppIcon.appiconset/167x167.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/AppIcon.appiconset/180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/AppIcon.appiconset/180x180.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/AppIcon.appiconset/20x20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/AppIcon.appiconset/20x20.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/AppIcon.appiconset/29x29.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/AppIcon.appiconset/29x29.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/AppIcon.appiconset/40x40 1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/AppIcon.appiconset/40x40 1.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/AppIcon.appiconset/40x40 2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/AppIcon.appiconset/40x40 2.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/AppIcon.appiconset/40x40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/AppIcon.appiconset/40x40.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/AppIcon.appiconset/58x58 1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/AppIcon.appiconset/58x58 1.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/AppIcon.appiconset/58x58.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/AppIcon.appiconset/58x58.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/AppIcon.appiconset/60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/AppIcon.appiconset/60x60.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/AppIcon.appiconset/76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/AppIcon.appiconset/76x76.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/AppIcon.appiconset/80x80 1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/AppIcon.appiconset/80x80 1.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/AppIcon.appiconset/80x80.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/AppIcon.appiconset/80x80.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/AppIcon.appiconset/87x87.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/AppIcon.appiconset/87x87.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/Avatars/Avatar Default.imageset/Avatar Default.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/Avatars/Avatar Default.imageset/Avatar Default.jpg -------------------------------------------------------------------------------- /hello/Assets.xcassets/Avatars/Avatar Default.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "Avatar Default.jpg", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/Avatars/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/Backgrounds/Background1.imageset/Background 1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/Backgrounds/Background1.imageset/Background 1.jpg -------------------------------------------------------------------------------- /hello/Assets.xcassets/Backgrounds/Background1.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "Background 1.jpg", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/Backgrounds/Background10.imageset/Background 10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/Backgrounds/Background10.imageset/Background 10.jpg -------------------------------------------------------------------------------- /hello/Assets.xcassets/Backgrounds/Background10.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "Background 10.jpg", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/Backgrounds/Background2.imageset/Background 2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/Backgrounds/Background2.imageset/Background 2.jpg -------------------------------------------------------------------------------- /hello/Assets.xcassets/Backgrounds/Background2.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "Background 2.jpg", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/Backgrounds/Background3.imageset/Background 3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/Backgrounds/Background3.imageset/Background 3.jpg -------------------------------------------------------------------------------- /hello/Assets.xcassets/Backgrounds/Background3.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "Background 3.jpg", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/Backgrounds/Background4.imageset/Background 4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/Backgrounds/Background4.imageset/Background 4.jpg -------------------------------------------------------------------------------- /hello/Assets.xcassets/Backgrounds/Background4.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "Background 4.jpg", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/Backgrounds/Background5.imageset/Background 5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/Backgrounds/Background5.imageset/Background 5.jpg -------------------------------------------------------------------------------- /hello/Assets.xcassets/Backgrounds/Background5.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "Background 5.jpg", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/Backgrounds/Background6.imageset/Background 6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/Backgrounds/Background6.imageset/Background 6.jpg -------------------------------------------------------------------------------- /hello/Assets.xcassets/Backgrounds/Background6.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "Background 6.jpg", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/Backgrounds/Background7.imageset/Background 7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/Backgrounds/Background7.imageset/Background 7.jpg -------------------------------------------------------------------------------- /hello/Assets.xcassets/Backgrounds/Background7.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "Background 7.jpg", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/Backgrounds/Background8.imageset/Background 8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/Backgrounds/Background8.imageset/Background 8.jpg -------------------------------------------------------------------------------- /hello/Assets.xcassets/Backgrounds/Background8.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "Background 8.jpg", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/Backgrounds/Background9.imageset/Background 9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/Backgrounds/Background9.imageset/Background 9.jpg -------------------------------------------------------------------------------- /hello/Assets.xcassets/Backgrounds/Background9.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "Background 9.jpg", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/Backgrounds/Blob1.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "Blob 1.pdf", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "appearances" : [ 10 | { 11 | "appearance" : "luminosity", 12 | "value" : "dark" 13 | } 14 | ], 15 | "filename" : "Blob 1 Dark.pdf", 16 | "idiom" : "universal", 17 | "scale" : "1x" 18 | }, 19 | { 20 | "idiom" : "universal", 21 | "scale" : "2x" 22 | }, 23 | { 24 | "appearances" : [ 25 | { 26 | "appearance" : "luminosity", 27 | "value" : "dark" 28 | } 29 | ], 30 | "idiom" : "universal", 31 | "scale" : "2x" 32 | }, 33 | { 34 | "idiom" : "universal", 35 | "scale" : "3x" 36 | }, 37 | { 38 | "appearances" : [ 39 | { 40 | "appearance" : "luminosity", 41 | "value" : "dark" 42 | } 43 | ], 44 | "idiom" : "universal", 45 | "scale" : "3x" 46 | } 47 | ], 48 | "info" : { 49 | "author" : "xcode", 50 | "version" : 1 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/Backgrounds/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/Backgrounds/Illustration.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "Illustration 5.png", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/Backgrounds/Illustration.imageset/Illustration 5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/Backgrounds/Illustration.imageset/Illustration 5.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/Backgrounds/Waves1.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "Waves 1.pdf", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "appearances" : [ 10 | { 11 | "appearance" : "luminosity", 12 | "value" : "dark" 13 | } 14 | ], 15 | "filename" : "Waves 1 Dark.pdf", 16 | "idiom" : "universal", 17 | "scale" : "1x" 18 | }, 19 | { 20 | "idiom" : "universal", 21 | "scale" : "2x" 22 | }, 23 | { 24 | "appearances" : [ 25 | { 26 | "appearance" : "luminosity", 27 | "value" : "dark" 28 | } 29 | ], 30 | "idiom" : "universal", 31 | "scale" : "2x" 32 | }, 33 | { 34 | "idiom" : "universal", 35 | "scale" : "3x" 36 | }, 37 | { 38 | "appearances" : [ 39 | { 40 | "appearance" : "luminosity", 41 | "value" : "dark" 42 | } 43 | ], 44 | "idiom" : "universal", 45 | "scale" : "3x" 46 | } 47 | ], 48 | "info" : { 49 | "author" : "xcode", 50 | "version" : 1 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/Backgrounds/Waves2.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "Waves 2.pdf", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "appearances" : [ 10 | { 11 | "appearance" : "luminosity", 12 | "value" : "dark" 13 | } 14 | ], 15 | "filename" : "Waves 2 Dark.pdf", 16 | "idiom" : "universal", 17 | "scale" : "1x" 18 | }, 19 | { 20 | "idiom" : "universal", 21 | "scale" : "2x" 22 | }, 23 | { 24 | "appearances" : [ 25 | { 26 | "appearance" : "luminosity", 27 | "value" : "dark" 28 | } 29 | ], 30 | "idiom" : "universal", 31 | "scale" : "2x" 32 | }, 33 | { 34 | "idiom" : "universal", 35 | "scale" : "3x" 36 | }, 37 | { 38 | "appearances" : [ 39 | { 40 | "appearance" : "luminosity", 41 | "value" : "dark" 42 | } 43 | ], 44 | "idiom" : "universal", 45 | "scale" : "3x" 46 | } 47 | ], 48 | "info" : { 49 | "author" : "xcode", 50 | "version" : 1 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/Colors/Background.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "color" : { 5 | "color-space" : "srgb", 6 | "components" : { 7 | "alpha" : "1.000", 8 | "blue" : "0xFF", 9 | "green" : "0xF6", 10 | "red" : "0xF2" 11 | } 12 | }, 13 | "idiom" : "universal" 14 | }, 15 | { 16 | "appearances" : [ 17 | { 18 | "appearance" : "luminosity", 19 | "value" : "dark" 20 | } 21 | ], 22 | "color" : { 23 | "color-space" : "srgb", 24 | "components" : { 25 | "alpha" : "1.000", 26 | "blue" : "0x4B", 27 | "green" : "0x25", 28 | "red" : "0x25" 29 | } 30 | }, 31 | "idiom" : "universal" 32 | } 33 | ], 34 | "info" : { 35 | "author" : "xcode", 36 | "version" : 1 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/Colors/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/Colors/Shadow.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "color" : { 5 | "color-space" : "srgb", 6 | "components" : { 7 | "alpha" : "1.000", 8 | "blue" : "0x7C", 9 | "green" : "0x2A", 10 | "red" : "0x45" 11 | } 12 | }, 13 | "idiom" : "universal" 14 | }, 15 | { 16 | "appearances" : [ 17 | { 18 | "appearance" : "luminosity", 19 | "value" : "dark" 20 | } 21 | ], 22 | "color" : { 23 | "color-space" : "srgb", 24 | "components" : { 25 | "alpha" : "1.000", 26 | "blue" : "0x00", 27 | "green" : "0x00", 28 | "red" : "0x00" 29 | } 30 | }, 31 | "idiom" : "universal" 32 | } 33 | ], 34 | "info" : { 35 | "author" : "xcode", 36 | "version" : 1 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/Documents/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/Documents/create_project_1.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "create_project_1.jpg", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/Documents/create_project_1.imageset/create_project_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/Documents/create_project_1.imageset/create_project_1.jpg -------------------------------------------------------------------------------- /hello/Assets.xcassets/Documents/create_project_2.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "create_project_2.jpg", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/Documents/create_project_2.imageset/create_project_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/Documents/create_project_2.imageset/create_project_2.jpg -------------------------------------------------------------------------------- /hello/Assets.xcassets/Documents/create_project_3.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "create_project_3.jpg", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/Documents/create_project_3.imageset/create_project_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/Documents/create_project_3.imageset/create_project_3.jpg -------------------------------------------------------------------------------- /hello/Assets.xcassets/Documents/create_project_4.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "create_project_4.jpg", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/Documents/create_project_4.imageset/create_project_4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/Documents/create_project_4.imageset/create_project_4.jpg -------------------------------------------------------------------------------- /hello/Assets.xcassets/Documents/hello.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "hello.jpg", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/Documents/hello.imageset/hello.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/Documents/hello.imageset/hello.jpg -------------------------------------------------------------------------------- /hello/Assets.xcassets/Home/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/Home/icon_lang.imageset/180x180 1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/Home/icon_lang.imageset/180x180 1.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/Home/icon_lang.imageset/180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/Home/icon_lang.imageset/180x180.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/Home/icon_lang.imageset/80x80.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/Home/icon_lang.imageset/80x80.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/Home/icon_lang.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "80x80.png", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "filename" : "180x180.png", 10 | "idiom" : "universal", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "filename" : "180x180 1.png", 15 | "idiom" : "universal", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "author" : "xcode", 21 | "version" : 1 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/Home/icon_sdk.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "sdk.svg", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "filename" : "sdk 1.svg", 10 | "idiom" : "universal", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "filename" : "sdk 2.svg", 15 | "idiom" : "universal", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "author" : "xcode", 21 | "version" : 1 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/Home/icon_swift.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "icon_swift.png", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "filename" : "icon_swift 1.png", 10 | "idiom" : "universal", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "filename" : "icon_swift 2.png", 15 | "idiom" : "universal", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "author" : "xcode", 21 | "version" : 1 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/Home/icon_swift.imageset/icon_swift 1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/Home/icon_swift.imageset/icon_swift 1.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/Home/icon_swift.imageset/icon_swift 2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/Home/icon_swift.imageset/icon_swift 2.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/Home/icon_swift.imageset/icon_swift.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/Home/icon_swift.imageset/icon_swift.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/Home/icon_swiftui.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "icon_swiftui.png", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "filename" : "icon_swiftui 1.png", 10 | "idiom" : "universal", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "filename" : "icon_swiftui 2.png", 15 | "idiom" : "universal", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "author" : "xcode", 21 | "version" : 1 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/Home/icon_swiftui.imageset/icon_swiftui 1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/Home/icon_swiftui.imageset/icon_swiftui 1.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/Home/icon_swiftui.imageset/icon_swiftui 2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/Home/icon_swiftui.imageset/icon_swiftui 2.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/Home/icon_swiftui.imageset/icon_swiftui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/Home/icon_swiftui.imageset/icon_swiftui.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/example/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/example/car.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "car.png", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "filename" : "car 1.png", 10 | "idiom" : "universal", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "filename" : "car 2.png", 15 | "idiom" : "universal", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "author" : "xcode", 21 | "version" : 1 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/example/car.imageset/car 1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/example/car.imageset/car 1.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/example/car.imageset/car 2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/example/car.imageset/car 2.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/example/car.imageset/car.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/example/car.imageset/car.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/icon/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/icon/code.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "code.png", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "filename" : "code128.png", 10 | "idiom" : "universal", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "filename" : "code256.png", 15 | "idiom" : "universal", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "author" : "xcode", 21 | "version" : 1 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/icon/code.imageset/code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/icon/code.imageset/code.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/icon/code.imageset/code128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/icon/code.imageset/code128.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/icon/code.imageset/code256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/icon/code.imageset/code256.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/icon/search.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "search.png", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "filename" : "search-1.png", 10 | "idiom" : "universal", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "filename" : "search-2.png", 15 | "idiom" : "universal", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "author" : "xcode", 21 | "version" : 1 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/icon/search.imageset/search-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/icon/search.imageset/search-1.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/icon/search.imageset/search-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/icon/search.imageset/search-2.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/icon/search.imageset/search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/icon/search.imageset/search.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/icon/shake.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "shake_128.png", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "filename" : "shake_256.png", 10 | "idiom" : "universal", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "filename" : "shake_512.png", 15 | "idiom" : "universal", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "author" : "xcode", 21 | "version" : 1 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/icon/shake.imageset/shake_128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/icon/shake.imageset/shake_128.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/icon/shake.imageset/shake_256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/icon/shake.imageset/shake_256.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/icon/shake.imageset/shake_512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/icon/shake.imageset/shake_512.png -------------------------------------------------------------------------------- /hello/Assets.xcassets/icon/start.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "start.jpeg", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /hello/Assets.xcassets/icon/start.imageset/start.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Assets.xcassets/icon/start.imageset/start.jpeg -------------------------------------------------------------------------------- /hello/Common/Show_SwiftUI_Docs.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Show_SwiftUI_Docs.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/10/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct Show_SwiftUI_Docs: View { 11 | @State var available_versions: [String] = [] 12 | @State var desc: String = "" 13 | @State var declaration: String = "" 14 | 15 | var body: some View { 16 | VStack(alignment: .leading, spacing: 15) { 17 | Text(available_versions[0]) 18 | .font(.callout) 19 | .padding(.horizontal, 10) 20 | .foregroundColor(.gray) 21 | .overlay( 22 | Capsule(style: .continuous) 23 | .stroke(.gray, lineWidth: 1) 24 | ) 25 | 26 | Text(desc) 27 | .font(.callout) 28 | 29 | Group { 30 | Text(declaration) 31 | .font(.callout) 32 | .foregroundColor(.black.opacity(0.8)) 33 | 34 | .frame(maxWidth: .infinity, alignment: .leading) 35 | .padding(10) 36 | } 37 | .background(.regularMaterial) 38 | .cornerRadius(10) 39 | } 40 | .padding() 41 | } 42 | } 43 | 44 | struct Show_SwiftUI_Docs_Previews: PreviewProvider { 45 | static var previews: some View { 46 | Show_SwiftUI_Docs() 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /hello/Common/loadLocalHtml.swift: -------------------------------------------------------------------------------- 1 | // 2 | // loadLocalHtml.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/10/22. 6 | // 7 | 8 | import SwiftUI 9 | import WebKit 10 | 11 | fileprivate struct loadLocalHtmlFile: UIViewRepresentable { 12 | var filename: String 13 | var filedir: String 14 | 15 | func makeUIView(context: Context) -> WKWebView { 16 | return WKWebView() 17 | } 18 | 19 | func updateUIView(_ uiView: WKWebView, context: Context) { 20 | let fdir = filedir.isEmpty ? "/Resouces.bundle/" : "/Resouces.bundle/\(filedir)/" 21 | let fileURL = Bundle.main.url(forResource: filename, withExtension: ".html", subdirectory: fdir) 22 | if fileURL == nil { 23 | return 24 | } 25 | uiView.loadFileURL(fileURL!, allowingReadAccessTo: fileURL!) 26 | 27 | let request = URLRequest(url: fileURL!) 28 | 29 | uiView.load(request) 30 | 31 | uiView.allowsBackForwardNavigationGestures = true 32 | } 33 | } 34 | 35 | struct loadLocalHtml: View { 36 | @State var pageTitle: String = "" 37 | @State var filedir: String = "" 38 | @State var filename: String = "" 39 | 40 | var body: some View { 41 | VStack { 42 | loadLocalHtmlFile(filename: filename, filedir: filedir) 43 | } 44 | .navigationTitle(pageTitle) 45 | .navigationBarTitleDisplayMode(.inline) 46 | .ignoresSafeArea(edges: .bottom) 47 | } 48 | } 49 | 50 | struct loadLocalHtml_Previews: PreviewProvider { 51 | static var previews: some View { 52 | loadLocalHtml() 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /hello/Common/loadMarkDownInHtml.swift: -------------------------------------------------------------------------------- 1 | // 2 | // loadMarkDownInHtml.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/20/22. 6 | // 7 | 8 | import SwiftUI 9 | import WebKit 10 | 11 | struct loadLocalHtmlForMarkdown: UIViewRepresentable { 12 | // var filename: String 13 | // var filedir: String 14 | 15 | func makeUIView(context: Context) -> WKWebView { 16 | return WKWebView() 17 | } 18 | 19 | func updateUIView(_ uiView: WKWebView, context: Context) { 20 | let fdir = "/Resouces.bundle/App" 21 | let fileURL = Bundle.main.url(forResource: "main.html", withExtension: nil, subdirectory: fdir) 22 | if fileURL == nil { 23 | return 24 | } 25 | uiView.loadFileURL(fileURL!, allowingReadAccessTo: fileURL!) 26 | 27 | var url = "\(fileURL!)#firstSight/introduce" 28 | print(url) 29 | let request = URLRequest(url: URL(string: url)!) 30 | 31 | uiView.load(request) 32 | 33 | uiView.allowsBackForwardNavigationGestures = true 34 | } 35 | } 36 | 37 | // 在html中加载markdown文件 38 | struct loadMarkDownInHtml: View { 39 | @State var pageTitle: String = "" 40 | @State var filedir: String = "" 41 | @State var filename: String = "" 42 | 43 | var body: some View { 44 | VStack { 45 | // loadLocalHtmlForMarkdown(filename: filename, filedir: filedir) 46 | loadLocalHtmlForMarkdown() 47 | } 48 | .navigationTitle(pageTitle) 49 | .navigationBarTitleDisplayMode(.inline) 50 | .ignoresSafeArea(edges: .bottom) 51 | } 52 | } 53 | 54 | struct loadMarkDownInHtml_Previews: PreviewProvider { 55 | static var previews: some View { 56 | loadMarkDownInHtml() 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /hello/Common/loadOpenUrl.swift: -------------------------------------------------------------------------------- 1 | // 2 | // loadOpenUrl.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/8/22. 6 | // 7 | 8 | import SwiftUI 9 | import WebKit 10 | 11 | fileprivate struct loadRemoteURL: UIViewRepresentable { 12 | var url: URL 13 | 14 | func makeUIView(context: Context) -> WKWebView { 15 | return WKWebView() 16 | } 17 | 18 | func updateUIView(_ uiView: WKWebView, context: Context) { 19 | let request = URLRequest(url: url) 20 | uiView.load(request) 21 | uiView.allowsBackForwardNavigationGestures = true 22 | } 23 | } 24 | 25 | // 在webview打开远程地址URL 26 | struct loadOpenUrl: View { 27 | @State var url: String = "" 28 | @State var title: String = "" 29 | 30 | var body: some View { 31 | loadRemoteURL(url: URL(string: self.url)!) 32 | .edgesIgnoringSafeArea([.bottom]) 33 | .navigationTitle(title) 34 | .navigationBarTitleDisplayMode(.inline) 35 | } 36 | } 37 | 38 | struct loadOpenUrl_Previews: PreviewProvider { 39 | static var previews: some View { 40 | loadOpenUrl() 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /hello/Common/urlRequest1.swift: -------------------------------------------------------------------------------- 1 | // 2 | // urlRequest.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 8/25/22. 6 | // 7 | 8 | import SwiftUI 9 | import Swift 10 | import Network 11 | 12 | enum NetworkError: String { 13 | case notNetwork = "无网络,请检查网络设置" 14 | case urlInvalid = "URL无效" 15 | case httpStatusCodeError = "HTTP状态码错误" 16 | case codeRunException = "代码运行异常" 17 | } 18 | 19 | public func urlGet(url: String, resType: String = "json") async -> [String:Any] { 20 | var result: Dictionary = ["status": false, "message": "" ] 21 | 22 | guard let url = URL(string: url) else { 23 | result["message"] = NetworkError.urlInvalid.rawValue 24 | return result 25 | } 26 | 27 | do { 28 | let (data, response) = try await URLSession.shared.data(from: url) 29 | 30 | guard let httpResponse = response as? HTTPURLResponse, httpResponse.statusCode == 200 else { 31 | result["message"] = NetworkError.httpStatusCodeError.rawValue 32 | return result 33 | } 34 | 35 | if data == data { 36 | result["status"] = true 37 | if (resType == "json") { 38 | result["data"] = try JSONSerialization.jsonObject(with: data, options: []) as! [String:Any] 39 | } else if (resType == "str") { 40 | result["data"] = data 41 | } else { 42 | result["data"] = String(data: data, encoding: .utf8)! 43 | } 44 | } 45 | } catch let error { 46 | print(error) 47 | result["message"] = NetworkError.codeRunException.rawValue 48 | } 49 | return result 50 | } 51 | -------------------------------------------------------------------------------- /hello/Common/urlRequest2.swift: -------------------------------------------------------------------------------- 1 | // 2 | // urlRequest.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 8/25/22. 6 | // 7 | 8 | import SwiftUI 9 | import Swift 10 | import Network 11 | 12 | public enum URLSessionAsyncErrors: Error { 13 | case invalidUrlResponse, missingResponseData 14 | } 15 | 16 | public extension URLSession { 17 | func asyncFunc(from url: URL) async throws -> (Data, URLResponse) { 18 | return try await withCheckedThrowingContinuation { continuation in 19 | let task = URLSession.shared.dataTask(with: url) { data, response, error in 20 | if let error = error { 21 | continuation.resume(throwing: error) 22 | return 23 | } 24 | guard let response = response as? HTTPURLResponse else { 25 | continuation.resume(throwing: URLSessionAsyncErrors.invalidUrlResponse) 26 | return 27 | } 28 | guard let data = data else { 29 | continuation.resume(throwing: URLSessionAsyncErrors.missingResponseData) 30 | return 31 | } 32 | continuation.resume(returning: (data, response)) 33 | } 34 | task.resume() 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /hello/Common/viewExtension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // viewExtension.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/13/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | extension View { 11 | func backgroundColor(_ color: Color) -> some View { 12 | return self.background(color) 13 | } 14 | } 15 | 16 | extension View { 17 | func textCallout() -> some View { 18 | return 19 | self.font(.callout) 20 | .foregroundColor(.gray) 21 | } 22 | } 23 | 24 | extension View { 25 | func navBarViewSource_View(_ name: String) -> some View { 26 | return 27 | 28 | self.navigationBarItems( 29 | trailing: 30 | Menu { 31 | Button(action: { 32 | 33 | }, label: { 34 | Label("查看源码", systemImage: "text.viewfinder") 35 | }) 36 | Button(action: { 37 | 38 | }, label: { 39 | Label("查看文档", systemImage: "doc.viewfinder") 40 | }) 41 | } label: { 42 | Label("Menu示例", systemImage: "ellipsis.circle") 43 | .labelStyle(.iconOnly) 44 | } 45 | ) 46 | } 47 | } 48 | 49 | -------------------------------------------------------------------------------- /hello/Components/Animation/Mask.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Mask.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 8/2/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct Mask: View { 11 | var body: some View { 12 | ZStack { 13 | LinearGradient(gradient: Gradient(colors: [Color(#colorLiteral(red: 0.2196078449, green: 0.007843137719, blue: 0.8549019694, alpha: 1)), Color(#colorLiteral(red: 0.2588235438, green: 0.7568627596, blue: 0.9686274529, alpha: 1))]), startPoint: .topLeading, endPoint: .bottomTrailing) 14 | .ignoresSafeArea() 15 | 16 | VStack { 17 | ForEach(0 ..< 5) { item in 18 | Text("Mask and Transparency") 19 | .font(.title3).bold() 20 | .padding(.vertical) 21 | .frame(maxWidth: .infinity, alignment: .leading) 22 | Divider() 23 | } 24 | } 25 | .frame(height: 300, alignment: .top) 26 | .padding() 27 | .background(Color.white) 28 | .mask( 29 | LinearGradient(gradient: Gradient(colors: [Color.black, Color.black, Color.black, Color.black.opacity(0)]), startPoint: .top, endPoint: .bottom) 30 | ) 31 | .cornerRadius(30) 32 | .padding() 33 | } 34 | .navigationTitle(".mask") 35 | .navigationBarTitleDisplayMode(.inline) 36 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "mask")) 37 | } 38 | } 39 | 40 | struct Mask_Previews: PreviewProvider { 41 | static var previews: some View { 42 | Mask() 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /hello/Components/Animation/Shadow.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Shadow.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 8/2/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct Shadow: View { 11 | var body: some View { 12 | VStack { 13 | VStack { 14 | Text("hello") 15 | .font(.title.bold()) 16 | .foregroundColor(.white) 17 | .shadow(radius: 20) 18 | } 19 | .frame(width: 300,height: 400) 20 | .background(.pink) 21 | .cornerRadius(20) 22 | .shadow(color: .black.opacity(0.3), radius: 5, x:0, y: 2) 23 | .shadow(color: .pink.opacity(0.3), radius: 20, x:0, y:10) 24 | 25 | Text("备注:本页面主要运用了.shadow") 26 | .font(.footnote) 27 | .offset(y: 20) 28 | } 29 | .navigationTitle(".shadow") 30 | .navigationBarTitleDisplayMode(.inline) 31 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "shadow")) 32 | } 33 | } 34 | 35 | struct Shadow_Previews: PreviewProvider { 36 | static var previews: some View { 37 | Shadow() 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /hello/Components/Animation/Transitions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Transitions.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 8/2/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct Transitions: View { 11 | @State var show = false 12 | 13 | var body: some View { 14 | VStack { 15 | ZStack { 16 | if !show { 17 | Text("View Transition") 18 | .padding() 19 | .background(Capsule().stroke()) 20 | 21 | Text("备注:本页面主要用到了 .transition(.move(edge: .top))") 22 | .font(.footnote) 23 | .offset(y: 60) 24 | } else { 25 | RoundedRectangle(cornerRadius: 30) 26 | .fill(Color.blue) 27 | .padding() 28 | .transition(.move(edge: .top)) 29 | .zIndex(1) 30 | } 31 | } 32 | .onTapGesture { 33 | withAnimation(.spring()) { 34 | show.toggle() 35 | } 36 | } 37 | } 38 | .navigationTitle(".transition") 39 | .navigationBarTitleDisplayMode(.inline) 40 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "transition")) 41 | } 42 | } 43 | 44 | struct Transitions_Previews: PreviewProvider { 45 | static var previews: some View { 46 | Transitions() 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /hello/Components/Animation/a_withAnimation.swift: -------------------------------------------------------------------------------- 1 | // 2 | // a_withAnimation.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 8/2/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct a_withAnimation: View { 11 | @State var show: Bool = false 12 | 13 | var body: some View { 14 | VStack { 15 | VStack { 16 | Text("hello") 17 | .font(.title.bold()) 18 | .foregroundColor(.white) 19 | } 20 | .frame(width: show ? 150: 200, height: show ? 50 : 80) 21 | .background(.blue) 22 | .cornerRadius(30) 23 | .shadow(color: .blue.opacity(0.3), radius: 20) 24 | .onTapGesture { 25 | withAnimation(.spring()) { 26 | show.toggle() 27 | } 28 | } 29 | 30 | Text("备注:本页面主要展示withAnimation()的使用") 31 | .font(.footnote) 32 | .offset(y: 30) 33 | } 34 | .navigationTitle("withAnimation") 35 | .navigationBarTitleDisplayMode(.inline) 36 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "withAnimation")) 37 | } 38 | } 39 | 40 | struct a_withAnimation_Previews: PreviewProvider { 41 | static var previews: some View { 42 | a_withAnimation() 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /hello/Components/Gesture/v_DragGesture.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_DragGesture.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/12/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_DragGesture: View { 11 | @State var viewState = CGSize.zero 12 | 13 | var drag: some Gesture { 14 | DragGesture() 15 | .onChanged { value in 16 | viewState = value.translation 17 | } 18 | .onEnded { value in 19 | withAnimation(.spring()) { 20 | viewState = .zero 21 | } 22 | } 23 | } 24 | 25 | var body: some View { 26 | VStack(spacing: 30) { 27 | 28 | RoundedRectangle(cornerRadius: 30) 29 | .fill(Color.pink) 30 | .frame(width: 50, height: 50) 31 | .offset(x: viewState.width, y: viewState.height) 32 | .gesture( 33 | drag 34 | ) 35 | 36 | Text("将手指放到图标上,然后拖到其它地方试试。") 37 | .font(.body) 38 | 39 | Text("本示例主要演示 DragGesture() 的用法。") 40 | .font(.callout) 41 | .foregroundColor(.secondary) 42 | } 43 | .padding() 44 | .navigationTitle("拖曳 - DragGesture") 45 | .navigationBarTitleDisplayMode(.inline) 46 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "DragGesture")) 47 | } 48 | } 49 | 50 | struct v_DragGesture_Previews: PreviewProvider { 51 | static var previews: some View { 52 | v_DragGesture() 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /hello/Components/Gesture/v_MagnificationGesture.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_MagnificationGesture.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/12/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_MagnificationGesture: View { 11 | @State private var currentAmount = 0.0 12 | @State private var finalAmount = 1.0 13 | 14 | var body: some View { 15 | VStack(spacing: 30) { 16 | 17 | RoundedRectangle(cornerRadius: 30) 18 | .fill(Color.yellow) 19 | .frame(width: 120, height: 120, alignment: .center) 20 | .scaleEffect(finalAmount + currentAmount) 21 | .gesture( 22 | MagnificationGesture() 23 | .onChanged { amount in 24 | currentAmount = amount - 1 25 | } 26 | .onEnded { amount in 27 | finalAmount += currentAmount 28 | currentAmount = 0 29 | } 30 | ) 31 | 32 | Text("将双指放到图标上,然后向外分离。") 33 | .font(.body) 34 | 35 | Text("本示例主要演示 MagnificationGesture() 的用法。") 36 | .font(.callout) 37 | .foregroundColor(.secondary) 38 | } 39 | .padding() 40 | .navigationTitle("MagnificationGesture") 41 | .navigationBarTitleDisplayMode(.inline) 42 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "MagnificationGesture")) 43 | } 44 | } 45 | 46 | struct v_MagnificationGesture_Previews: PreviewProvider { 47 | static var previews: some View { 48 | v_MagnificationGesture() 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /hello/Components/Gesture/v_RotationGesture.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_RotationGesture.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/12/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_RotationGesture: View { 11 | @State private var currentAngle: Angle = .degrees(0) 12 | @State private var finalAngle: Angle = .degrees(0) 13 | 14 | var rotation: some Gesture { 15 | RotationGesture() 16 | .onChanged { angle in 17 | self.currentAngle = angle 18 | } 19 | .onEnded { angle in 20 | self.finalAngle += self.currentAngle 21 | self.currentAngle = .degrees(0) 22 | } 23 | } 24 | 25 | var body: some View { 26 | VStack(spacing: 30) { 27 | 28 | RoundedRectangle(cornerRadius: 30) 29 | .fill(Color.green) 30 | .frame(width: 120, height: 120) 31 | .rotationEffect(currentAngle + finalAngle) 32 | .gesture( 33 | rotation 34 | ) 35 | 36 | Text("双指在图标上旋转试试") 37 | .font(.body) 38 | 39 | Text("本示例主要演示 RotationGesture() 的用法。") 40 | .font(.callout) 41 | .foregroundColor(.secondary) 42 | } 43 | .padding() 44 | .frame(maxWidth: .infinity) 45 | .navigationTitle("旋转 - RotationGesture") 46 | .navigationBarTitleDisplayMode(.inline) 47 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "RotationGesture")) 48 | } 49 | } 50 | 51 | struct v_RotationGesture_Previews: PreviewProvider { 52 | static var previews: some View { 53 | v_RotationGesture() 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /hello/Components/Gesture/v_SpatialTapGesture.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_SpatialTapGesture.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/12/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | 11 | struct v_SpatialTapGesture: View { 12 | @State private var location: CGPoint = .zero 13 | 14 | 15 | @available(iOS 16.0, *) 16 | var tap: some Gesture { 17 | SpatialTapGesture() 18 | .onEnded { event in 19 | self.location = event.location 20 | } 21 | } 22 | 23 | var body: some View { 24 | VStack(spacing: 30) { 25 | 26 | if #available(iOS 16.0, *) { 27 | Circle() 28 | .fill(self.location.y > 50 ? Color.blue : Color.red) 29 | .frame(width: 100, height: 100, alignment: .center) 30 | .gesture( 31 | tap 32 | ) 33 | } 34 | 35 | Text("根据点击位置切换颜色") 36 | .font(.body) 37 | 38 | Text("本示例主要演示 SpatialTapGesture() 的用法。\nSpatialTapGesture() 仅在iOS 16.0+系统生效") 39 | .font(.callout) 40 | .foregroundColor(.secondary) 41 | } 42 | .padding() 43 | .navigationTitle("SpatialTapGesture") 44 | .navigationBarTitleDisplayMode(.inline) 45 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "SpatialTapGesture")) 46 | } 47 | } 48 | 49 | struct v_SpatialTapGesture_Previews: PreviewProvider { 50 | static var previews: some View { 51 | v_SpatialTapGesture() 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /hello/Components/Gesture/v_onLongPressGesture.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_onLongPressGesture.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/12/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_onLongPressGesture: View { 11 | @State var isLongPress: Bool = false 12 | 13 | var body: some View { 14 | VStack(spacing: 30) { 15 | 16 | Image(systemName: "cloud.moon.rain.fill") 17 | .foregroundColor(.white) 18 | .font(.largeTitle) 19 | .background(isLongPress ? Color.pink : Color.blue) 20 | .mask(Circle()) 21 | .onLongPressGesture(minimumDuration: 2) { 22 | self.isLongPress.toggle() 23 | } 24 | 25 | Text("长按2S,改变 icon 背景色。") 26 | .font(.body) 27 | 28 | Text("本示例主要演示 .onLongPressGesture() 的用法。") 29 | .font(.callout) 30 | .foregroundColor(.secondary) 31 | } 32 | .padding() 33 | .navigationTitle("onLongPressGesture") 34 | .navigationBarTitleDisplayMode(.inline) 35 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "onLongPressGesture")) 36 | } 37 | } 38 | 39 | struct v_onLongPressGesture_Previews: PreviewProvider { 40 | static var previews: some View { 41 | v_onLongPressGesture() 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /hello/Components/Gesture/v_onTapGesture.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_onTapGesture.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/12/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_onTapGesture: View { 11 | @State private var isTap: Bool = false 12 | 13 | var body: some View { 14 | VStack(spacing: 30) { 15 | 16 | Image(systemName: "heart.circle.fill") 17 | .foregroundColor(isTap ? .red : .black) 18 | .font(.largeTitle) 19 | .onTapGesture { 20 | withAnimation { 21 | self.isTap.toggle() 22 | } 23 | } 24 | 25 | Text("点击 icon, 可切换图标颜色") 26 | .font(.body) 27 | 28 | Text("本示例主要演示 .onTapGesture() 的用法。") 29 | .font(.callout) 30 | .foregroundColor(.secondary) 31 | } 32 | .padding() 33 | .navigationTitle("onTapGesture") 34 | .navigationBarTitleDisplayMode(.inline) 35 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "onTapGesture")) 36 | } 37 | } 38 | 39 | struct v_onTapGesture_Previews: PreviewProvider { 40 | static var previews: some View { 41 | v_onTapGesture() 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /hello/Components/Image/v_image_AsyncImage.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_image_AsyncImage.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/14/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_image_AsyncImage: View { 11 | var body: some View { 12 | VStack { 13 | AsyncImage(url: URL(string: "https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png")) { image in 14 | image.resizable() 15 | } placeholder: { 16 | ProgressView() 17 | } 18 | .frame(height: 200) 19 | 20 | Text("备注:本图片是采用AsyncImage从网络下载, AsyncImage适用于iOS 15.0+") 21 | .font(.callout) 22 | .padding() 23 | } 24 | .navigationTitle("使用AsyncImage下载图片") 25 | .navigationBarTitleDisplayMode(.inline) 26 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "ImageAsyncImage")) 27 | } 28 | } 29 | 30 | struct v_image_AsyncImage_Previews: PreviewProvider { 31 | static var previews: some View { 32 | v_image_AsyncImage() 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /hello/Components/Image/v_image_SF.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_image_SF.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/14/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_image_SF: View { 11 | var body: some View { 12 | VStack { 13 | Image(systemName: "leaf.fill") 14 | .foregroundColor(.green) 15 | } 16 | .navigationTitle("SF符号") 17 | .navigationBarTitleDisplayMode(.inline) 18 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "ImageSF")) 19 | } 20 | } 21 | 22 | struct v_image_SF_Previews: PreviewProvider { 23 | static var previews: some View { 24 | v_image_SF() 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /hello/Components/Image/v_image_local.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_image_local.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/14/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_image_local: View { 11 | var body: some View { 12 | VStack { 13 | Image("car") 14 | .resizable() 15 | .aspectRatio(contentMode: .fit) 16 | .frame(width: 256, height: 256) 17 | .scaledToFit() 18 | 19 | Text("备注:图片预先放置在项目Assets目录下") 20 | .font(.callout) 21 | } 22 | .navigationTitle("本地资源图片") 23 | .navigationBarTitleDisplayMode(.inline) 24 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "ImageLocal")) 25 | } 26 | } 27 | 28 | struct v_image_local_Previews: PreviewProvider { 29 | static var previews: some View { 30 | v_image_local() 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /hello/Components/Other/v_blur.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_blur.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/3/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_blur: View { 11 | var body: some View { 12 | VStack { 13 | Text("说明:本页面示例,主要代码为:.blur(radius: 3.0) ") 14 | .font(.caption) 15 | .foregroundColor(.gray) 16 | .frame(height: 80) 17 | 18 | Text("好好休息,健康第一") 19 | .blur(radius: 3.0) 20 | 21 | Image("code") 22 | .frame(width: 128, height: 128) 23 | .blur(radius: 10.0) 24 | } 25 | .navigationTitle(".blur") 26 | .navigationBarTitleDisplayMode(.inline) 27 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "blur")) 28 | } 29 | } 30 | 31 | struct v_blur_Previews: PreviewProvider { 32 | static var previews: some View { 33 | v_blur() 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /hello/Components/Other/v_statusBar.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_statusBar.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/3/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_statusBar: View { 11 | @State var hideStatusBar:Bool = false 12 | 13 | var body: some View { 14 | VStack { 15 | 16 | Text("简介:是否隐藏状态栏, 使用 .statusBarHidden(true)") 17 | .font(.caption) 18 | .foregroundColor(.gray) 19 | .frame(height: 80) 20 | 21 | Button("是否隐藏状态栏") { 22 | withAnimation { 23 | self.hideStatusBar.toggle() 24 | } 25 | } 26 | .buttonStyle(.borderedProminent) 27 | .statusBarHidden(hideStatusBar) 28 | 29 | } 30 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "statusBarHidden")) 31 | } 32 | } 33 | 34 | struct v_statusBar_Previews: PreviewProvider { 35 | static var previews: some View { 36 | v_statusBar() 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /hello/Components/Picker/v_ColorPicker.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_ColorPicker.swift 颜色选择器 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/5/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_ColorPicker: View { 11 | @State private var bgColor = Color.blue.opacity(0.5) 12 | 13 | var body: some View { 14 | VStack { 15 | HStack { 16 | RoundedRectangle(cornerRadius: 25) 17 | .frame(width: 120, height: 120) 18 | .foregroundColor(bgColor) 19 | .padding(.horizontal) 20 | } 21 | 22 | ColorPicker("请选择区域背景色", selection: $bgColor) 23 | .padding(.horizontal) 24 | } 25 | .frame(maxWidth: .infinity, maxHeight: .infinity) 26 | .navigationTitle("ColorPicker") 27 | .navigationBarTitleDisplayMode(.inline) 28 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "ColorPicker")) 29 | } 30 | } 31 | 32 | struct v_ColorPicker_Previews: PreviewProvider { 33 | static var previews: some View { 34 | v_ColorPicker() 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /hello/Components/Picker/v_MultiPicker.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_MultiPicker-.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/5/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_MultiPicker: View { 11 | let provList: Array = ["山西省"] 12 | let cityList: Array = ["临汾市", "长治市", "大同市", "运城市"] 13 | 14 | @State private var selectedProv: String = "山西省" 15 | @State private var selectedCity: String = "大同市" 16 | 17 | var body: some View { 18 | VStack { 19 | GeometryReader { geometry in 20 | HStack(spacing: 0) { 21 | Picker("selecte prov", selection: $selectedProv) { 22 | ForEach(provList, id: \.self) { item in 23 | Text(item) 24 | } 25 | } 26 | .pickerStyle(.wheel) 27 | .frame(width: geometry.size.width / 2, alignment: .center) 28 | .clipped() 29 | 30 | Picker("selecte prov", selection: $selectedCity) { 31 | ForEach(cityList, id: \.self) { item in 32 | Text(item) 33 | } 34 | } 35 | .pickerStyle(.wheel) 36 | .frame(width: geometry.size.width / 2, alignment: .center) 37 | .clipped() 38 | } 39 | } 40 | } 41 | .navigationTitle("多列选择器") 42 | .navigationBarTitleDisplayMode(.inline) 43 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "MultiPicker")) 44 | } 45 | } 46 | 47 | struct v_MultiPicker_Previews: PreviewProvider { 48 | static var previews: some View { 49 | v_MultiPicker() 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /hello/Components/Picker/v_pickerStyle_default.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_default_PickerStyle.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/5/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | enum Colors4: String, CaseIterable, Identifiable { 11 | case yellow 12 | case blue 13 | case white 14 | var id: Self { self } 15 | } 16 | 17 | struct v_pickerStyle_default: View { 18 | @State private var selectedColor: Colors4 = .white 19 | 20 | var body: some View { 21 | List { 22 | Section(header: Text("默认样式")) { 23 | Picker("Colors", selection: $selectedColor) { 24 | ForEach(Colors4.allCases) { item in 25 | Text(item.rawValue.capitalized) 26 | } 27 | } 28 | } 29 | } 30 | .navigationTitle("默认样式") 31 | .navigationBarTitleDisplayMode(.inline) 32 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "pickerStyleDefault")) 33 | } 34 | } 35 | 36 | struct v_pickerStyle_default_Previews: PreviewProvider { 37 | static var previews: some View { 38 | v_pickerStyle_default() 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /hello/Components/Picker/v_pickerStyle_inline.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_pickerStyle_inline.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/5/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | enum Colors1: String, CaseIterable, Identifiable { 11 | case yellow 12 | case blue 13 | case white 14 | var id: Self { self } 15 | } 16 | 17 | struct v_pickerStyle_inline: View { 18 | @State private var selectedColor: Colors1 = .white 19 | 20 | var body: some View { 21 | List { 22 | Section(header: Text("PickerStyle inline样式").textCase(.none)) { 23 | Picker("Colors", selection: $selectedColor) { 24 | ForEach(Colors1.allCases) { item in 25 | Text(item.rawValue.capitalized) 26 | } 27 | } 28 | .pickerStyle(.inline) 29 | } 30 | } 31 | .navigationTitle(".inline") 32 | .navigationBarTitleDisplayMode(.inline) 33 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "pickerStyleInline")) 34 | } 35 | } 36 | 37 | struct v_pickerStyle_inline_Previews: PreviewProvider { 38 | static var previews: some View { 39 | v_pickerStyle_inline() 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /hello/Components/Picker/v_pickerStyle_menu.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_pickerStyle_menu.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/5/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | enum Colors3: String, CaseIterable, Identifiable { 11 | case yellow 12 | case blue 13 | case white 14 | var id: Self { self } 15 | } 16 | 17 | struct v_pickerStyle_menu: View { 18 | @State private var selectedColor: Colors3 = .white 19 | 20 | var body: some View { 21 | List { 22 | Section(header: Text("pickerStyle .menu样式").textCase(.none)) { 23 | Picker("Colors", selection: $selectedColor) { 24 | ForEach(Colors3.allCases) { item in 25 | Text(item.rawValue.capitalized) 26 | } 27 | }.pickerStyle(.menu) 28 | } 29 | } 30 | .navigationTitle(".menu") 31 | .navigationBarTitleDisplayMode(.inline) 32 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "pickerStyleMenu")) 33 | } 34 | } 35 | 36 | struct v_pickerStyle_menu_Previews: PreviewProvider { 37 | static var previews: some View { 38 | v_pickerStyle_menu() 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /hello/Components/Picker/v_pickerStyle_segmented.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_pickerStyle_segmented.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/5/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | enum Colors2: String, CaseIterable, Identifiable { 11 | case yellow 12 | case blue 13 | case white 14 | var id: Self { self } 15 | } 16 | 17 | struct v_pickerStyle_segmented: View { 18 | @State private var selectedColor: Colors2 = .white 19 | 20 | var body: some View { 21 | List { 22 | Section(header: Text("pickerStyle .segmented样式").textCase(.none)) { 23 | Picker("Colors", selection: $selectedColor) { 24 | ForEach(Colors2.allCases) { item in 25 | Text(item.rawValue.capitalized) 26 | } 27 | }.pickerStyle(.segmented) 28 | } 29 | } 30 | .navigationTitle(".segmented") 31 | .navigationBarTitleDisplayMode(.inline) 32 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "pickerStyleSegmented")) 33 | } 34 | } 35 | 36 | struct v_pickerStyle_segmented_Previews: PreviewProvider { 37 | static var previews: some View { 38 | v_pickerStyle_segmented() 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /hello/Components/Picker/v_pickerStyle_wheel.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_wheelPicker.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/5/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | enum Colors5: String, CaseIterable, Identifiable { 11 | case yellow 12 | case blue 13 | case white 14 | var id: Self { self } 15 | } 16 | 17 | struct v_pickerStyle_wheel: View { 18 | @State private var isOpen: Bool = false 19 | @State private var selectedColor: Colors5 = .white 20 | 21 | var body: some View { 22 | List { 23 | Section(header: Text("pickerStyle .wheel样式").textCase(.none)) { 24 | Picker("Colors", selection: $selectedColor) { 25 | ForEach(Colors5.allCases) { item in 26 | Text(item.rawValue.capitalized) 27 | } 28 | }.pickerStyle(.wheel) 29 | } 30 | } 31 | .navigationTitle(".wheel") 32 | .navigationBarTitleDisplayMode(.inline) 33 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "pickerStyleWheel")) 34 | } 35 | } 36 | 37 | struct v_pickerStyle_wheel_Previews: PreviewProvider { 38 | static var previews: some View { 39 | v_pickerStyle_wheel() 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /hello/Components/Shapes/v_Capsule.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_Capsule.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/24/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_Capsule: View { 11 | var body: some View { 12 | VStack(spacing: 20) { 13 | 14 | Text("以下示例是对 Capsule() 的应用。") 15 | .foregroundColor(.gray) 16 | 17 | // 示例1 18 | Section(header: Text("示例1:Capsule() 150x150")) { 19 | Capsule() 20 | .fill(.pink) 21 | .frame(width: 150, height: 150) 22 | } 23 | 24 | // 示例2 25 | Section(header: Text("示例2:Capsule()结合offset、rotationEffect的应用 ")) { 26 | Capsule() 27 | .foregroundColor(.blue) 28 | .frame(width : 120, height: 60) 29 | .offset(x: 0, y: 60) 30 | .rotationEffect(.degrees(20)) 31 | .opacity(0.75) 32 | } 33 | } 34 | .padding() 35 | .navigationTitle("Capsule()") 36 | .navigationBarTitleDisplayMode(.inline) 37 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "Capsule")) 38 | } 39 | } 40 | 41 | struct v_Capsule_Previews: PreviewProvider { 42 | static var previews: some View { 43 | v_Capsule() 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /hello/Components/Shapes/v_CapsuleGroup.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_CapsuleGroup.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/24/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_CapsuleGroup: View { 11 | var body: some View { 12 | VStack(spacing: 100) { 13 | Text("Capsule()的组合使用") 14 | .foregroundColor(.gray) 15 | 16 | ZStack { 17 | NCapsule(color: .pink, degree: 0) 18 | NCapsule(color: .red, degree: 45) 19 | NCapsule(color: .yellow, degree: 90) 20 | NCapsule(color: .orange, degree: 135) 21 | NCapsule(color: .blue, degree: 180) 22 | NCapsule(color: .green, degree: 225) 23 | NCapsule(color: .purple, degree: 270) 24 | NCapsule(color: .accentColor, degree: 314) 25 | } 26 | } 27 | .navigationTitle("Capsule()") 28 | .navigationBarTitleDisplayMode(.inline) 29 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "CapsuleGroup")) 30 | } 31 | } 32 | 33 | struct NCapsule: View { 34 | var color : Color 35 | var degree : Double 36 | 37 | var body: some View { 38 | Capsule() 39 | .foregroundColor(color) 40 | .frame(width : 60, height: 90) 41 | .offset(x: 0, y: 60) 42 | .rotationEffect(.degrees(degree)) 43 | .opacity(0.75) 44 | } 45 | } 46 | 47 | struct v_CapsuleGroup_Previews: PreviewProvider { 48 | static var previews: some View { 49 | v_CapsuleGroup() 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /hello/Components/Shapes/v_CircleProgressBar.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_CircleProgressBar.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/24/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_CircleProgressBar: View { 11 | @State var progress: Double = 0.6666 12 | 13 | var body: some View { 14 | VStack { 15 | Text("圆形进度条") 16 | .frame(height: 100) 17 | 18 | ZStack { 19 | Circle() 20 | .stroke(lineWidth: 20.0) 21 | .opacity(0.3) 22 | .foregroundColor(Color.red) 23 | 24 | Circle() 25 | .trim(from: 0.0, to: CGFloat(min(self.progress, 1.0))) 26 | .stroke(style: StrokeStyle(lineWidth: 20.0, lineCap: .round, lineJoin: .round)) 27 | .foregroundColor(Color.red) 28 | .rotationEffect(Angle(degrees: 270.0)) 29 | //.animation(.linear) 30 | 31 | Text(String(format: "%.0f %%", min(self.progress, 1.0)*100.0)) 32 | .font(.largeTitle) 33 | .bold() 34 | } 35 | .frame(width: 200, height: 200) 36 | .navigationTitle("CircleProgressBar") 37 | .navigationBarTitleDisplayMode(.inline) 38 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "CircleProgressBar")) 39 | } 40 | 41 | } 42 | } 43 | 44 | struct v_CircleProgressBar_Previews: PreviewProvider { 45 | static var previews: some View { 46 | v_CircleProgressBar() 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /hello/Components/Shapes/v_Ellipse.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_Ellipse.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/24/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_Ellipse: View { 11 | var body: some View { 12 | VStack(spacing: 20) { 13 | 14 | Text("以下示例是对 Ellipse() 的应用。") 15 | .foregroundColor(.gray) 16 | 17 | // 示例1 18 | Ellipse() 19 | .fill(.green) 20 | .frame(width: 150, height: 150) 21 | .overlay( 22 | Text("150x150").foregroundColor(.white) 23 | ) 24 | 25 | // 示例2 26 | Ellipse() 27 | .fill(.green) 28 | .frame(width: 200, height: 100) 29 | .overlay( 30 | Text("200x100").foregroundColor(.white) 31 | ) 32 | } 33 | .navigationTitle("Ellipse()") 34 | .navigationBarTitleDisplayMode(.inline) 35 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "Ellipse")) 36 | } 37 | } 38 | 39 | struct v_Ellipse_Previews: PreviewProvider { 40 | static var previews: some View { 41 | v_Ellipse() 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /hello/Components/Shapes/v_Path.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_path.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/25/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_Path: View { 11 | var body: some View { 12 | VStack { 13 | Text("以下示例,是对Path的应用") 14 | .foregroundColor(.gray) 15 | .frame(height: 100, alignment: .center) 16 | 17 | Path { 18 | path in 19 | path.addEllipse(in: CGRect(x: 100, y: 80, width: 200, height: 200)) 20 | 21 | path.addRoundedRect(in: CGRect(x: 100, y: 120, width: 200, height: 200), cornerSize: CGSize(width: 10, height: 10)) 22 | 23 | path.addEllipse(in: CGRect(x: 100, y: 210, width: 200, height: 200)) 24 | } 25 | .fill(Color.pink) 26 | 27 | } 28 | .navigationTitle("Path") 29 | .navigationBarTitleDisplayMode(.inline) 30 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "Path")) 31 | } 32 | } 33 | 34 | struct v_Path_Previews: PreviewProvider { 35 | static var previews: some View { 36 | v_Path() 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /hello/Components/TextField/InputAccentColor.swift: -------------------------------------------------------------------------------- 1 | // 2 | // InputAccentColor.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/4/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct InputAccentColor: View { 11 | @State var inputText: String = "" 12 | 13 | var body: some View { 14 | VStack(alignment: .leading, spacing: 20) { 15 | 16 | Text("简介:关于光标颜色, iOS 13.0~6.0, 为:.accentColor()。iOS 16.0起,新增了 .tint()") 17 | .font(.caption) 18 | .foregroundColor(.gray) 19 | .frame(height: 80) 20 | 21 | Section("光标颜色") { 22 | if #available(iOS 16.0, *) { 23 | TextField("光标显示显示红色", text: $inputText) 24 | .textFieldStyle(.roundedBorder) 25 | .gaugeStyle(.linearCapacity) 26 | .accentColor(.red) 27 | .tint(.red) 28 | } else { 29 | TextField("光标显示显示红色", text: $inputText) 30 | .textFieldStyle(.roundedBorder) 31 | .accentColor(.red) 32 | } 33 | } 34 | 35 | Spacer() 36 | } 37 | .padding() 38 | .navigationTitle("accentColor") 39 | .navigationBarTitleDisplayMode(.inline) 40 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI", pageID: "InputAccentColor")) 41 | } 42 | } 43 | 44 | struct InputAccentColor_Previews: PreviewProvider { 45 | static var previews: some View { 46 | InputAccentColor() 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /hello/Components/TextField/InputAutoFocus.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TextFieldFocus.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/4/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | private let intro = "简介:SwiftUI FocusState 属性包装器,可以帮助我们判断该视图内的 TextField 是否获得焦点。通过focused将FocusState与特定的 TextField 关联起来" 11 | 12 | struct InputAutoFocus: View { 13 | @FocusState var isFocused: Bool 14 | @State private var inputText: String = "" 15 | 16 | var body: some View { 17 | VStack(alignment: .leading, spacing: 20) { 18 | 19 | Text(intro) 20 | .font(.caption) 21 | .foregroundColor(.gray) 22 | .frame(height: 80) 23 | 24 | Text("自动聚焦的输入框") 25 | TextField("placeholder", text: $inputText) 26 | .textFieldStyle(.roundedBorder) 27 | .focused($isFocused) 28 | .onChange(of: isFocused) { value in 29 | print("------------\(value)") 30 | } 31 | .onAppear { 32 | DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { 33 | isFocused = true 34 | } 35 | } 36 | 37 | Spacer() 38 | } 39 | .padding() 40 | .navigationTitle(".focused") 41 | .navigationBarTitleDisplayMode(.inline) 42 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI", pageID: "InputAutoFocus")) 43 | } 44 | } 45 | 46 | struct InputAutoFocus_Previews: PreviewProvider { 47 | static var previews: some View { 48 | InputAutoFocus() 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /hello/Components/TextField/InputBorder.swift: -------------------------------------------------------------------------------- 1 | // 2 | // InputBorder.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/4/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct InputBorder: View { 11 | @State var inputText: String = "" 12 | @State var inputStatus: Bool = false 13 | 14 | var body: some View { 15 | VStack(alignment: .leading, spacing: 20) { 16 | 17 | Section("边框颜色 .border()") { 18 | TextField("根据输入内容显示边框颜色", text: $inputText) { inputStatus in 19 | self.inputStatus = true 20 | } 21 | .textFieldStyle(.roundedBorder) 22 | .border(tipsBorder) 23 | } 24 | 25 | Spacer() 26 | } 27 | .padding() 28 | .navigationTitle(".border()") 29 | .navigationBarTitleDisplayMode(.inline) 30 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI", pageID: "InputBorder")) 31 | } 32 | 33 | // 输入框编辑状态 边框颜色 34 | var tipsBorder: some ShapeStyle { 35 | if inputStatus { 36 | return inputText.count < 1 ? Color.red : Color.green; 37 | } else { 38 | return Color.gray 39 | } 40 | } 41 | } 42 | 43 | struct InputBorder_Previews: PreviewProvider { 44 | static var previews: some View { 45 | InputBorder() 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /hello/Components/TextField/InputFormatter.swift: -------------------------------------------------------------------------------- 1 | // 2 | // InputFormatter.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/4/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct InputFormatter: View { 11 | @State var price:Double = 1.2 12 | 13 | let formatterPrice: NumberFormatter = { 14 | let formatter = NumberFormatter() 15 | formatter.numberStyle = .currency 16 | return formatter 17 | }() 18 | 19 | var body: some View { 20 | VStack(alignment: .leading, spacing: 20) { 21 | 22 | Section("格式化 formatter") { 23 | TextField("格式化数字为货币", value: $price, formatter: formatterPrice) 24 | .keyboardType(.decimalPad) 25 | .textFieldStyle(.roundedBorder) 26 | } 27 | 28 | Spacer() 29 | } 30 | .padding() 31 | .navigationTitle("formatter") 32 | .navigationBarTitleDisplayMode(.inline) 33 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI", pageID: "InputFormatter")) 34 | } 35 | } 36 | 37 | struct InputFormatter_Previews: PreviewProvider { 38 | static var previews: some View { 39 | InputFormatter() 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /hello/Components/TextField/InputOn.swift: -------------------------------------------------------------------------------- 1 | // 2 | // InputOn.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/5/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct InputOn: View { 11 | @State private var nickname: String = "" 12 | 13 | var body: some View { 14 | VStack(alignment: .leading) { 15 | Text("简介:本页面示例,主要用到了.onEditingChanged() 和 .onCommit()") 16 | .font(.caption) 17 | .foregroundColor(.gray) 18 | .frame(height: 80) 19 | 20 | TextField( 21 | "昵称", 22 | text: $nickname, 23 | onEditingChanged: { (isBegin) in 24 | if isBegin { 25 | print(":: onEditingChanged 开始输入") 26 | } else { 27 | print(":: onEditingChanged 完成输入") 28 | } 29 | }, 30 | onCommit: { 31 | print(":: onCommit") 32 | } 33 | ) 34 | .textFieldStyle(RoundedBorderTextFieldStyle()) 35 | .submitScope() // 限定作用域 36 | .onSubmit { 37 | print(":: onSubmit") 38 | } 39 | 40 | Spacer() 41 | } 42 | .padding() 43 | .navigationTitle("TextField on") 44 | .navigationBarTitleDisplayMode(.inline) 45 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI", pageID: "InputOn")) 46 | } 47 | } 48 | 49 | struct InputOn_Previews: PreviewProvider { 50 | static var previews: some View { 51 | InputOn() 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /hello/Components/TextField/InputSecureField.swift: -------------------------------------------------------------------------------- 1 | // 2 | // InputSecureField.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/4/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct InputSecureField: View { 11 | @State var password: String = "" 12 | 13 | var body: some View { 14 | VStack(alignment: .leading, spacing: 20) { 15 | 16 | Text("简介:本页面示例,主要用到了SecureField()") 17 | .font(.caption) 18 | .foregroundColor(.gray) 19 | .frame(height: 80) 20 | 21 | Section(header: Text("密码输入框 SecureField").padding(.horizontal, 5)) { 22 | SecureField("密码输入框", text: $password) 23 | .textContentType(.password) 24 | .textFieldStyle(.roundedBorder) 25 | } 26 | 27 | Spacer() 28 | } 29 | .padding() 30 | .navigationTitle("SecureField") 31 | .navigationBarTitleDisplayMode(.inline) 32 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI", pageID: "InputSecureField")) 33 | } 34 | } 35 | 36 | struct InputSecureField_Previews: PreviewProvider { 37 | static var previews: some View { 38 | InputSecureField() 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /hello/Components/TextField/InputStyle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // InputStyle.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/5/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | private let intro: String = "简介: iOS上,textFieldStyle, 有3种样式: .automation、.plain、.roundedBorder。当然,您也可以自定义Style。遵行TextFieldStyle协议,重写_body方法即可" 11 | 12 | struct InputStyle: View { 13 | @State var inputText: String = "" 14 | 15 | var body: some View { 16 | VStack(alignment: .leading, spacing: 20) { 17 | 18 | Text(intro) 19 | .font(.caption) 20 | .foregroundColor(.gray) 21 | .frame(height: 80) 22 | 23 | Section(".automatic") { 24 | TextField("placeholder", text: $inputText) 25 | .textFieldStyle(.automatic) 26 | } 27 | 28 | Section(".plain") { 29 | TextField("placeholder", text: $inputText) 30 | .textFieldStyle(.plain) 31 | } 32 | 33 | Section(".roundedBorder") { 34 | TextField("placeholder", text: $inputText) 35 | .textFieldStyle(.roundedBorder) 36 | } 37 | 38 | Spacer() 39 | } 40 | .padding() 41 | .navigationTitle("textFieldStyle") 42 | .navigationBarTitleDisplayMode(.inline) 43 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI", pageID: "InputStyle")) 44 | } 45 | } 46 | 47 | struct InputStyle_Previews: PreviewProvider { 48 | static var previews: some View { 49 | InputStyle() 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /hello/Components/chart_PointMark.swift: -------------------------------------------------------------------------------- 1 | // 2 | // chart_PointMark.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 8/1/22. 6 | // 7 | 8 | #if canImport(Charts) 9 | import Charts 10 | #endif 11 | import SwiftUI 12 | 13 | struct SalaryItem: Identifiable { 14 | let Mon: String 15 | let value: Float 16 | 17 | var id:String { Mon } 18 | } 19 | 20 | let Salarys: [SalaryItem] = [ 21 | .init(Mon: "1月", value: 800.0), 22 | .init(Mon: "1月", value: 850.1), 23 | .init(Mon: "3月", value: 880.0), 24 | .init(Mon: "4月", value: 985.8), 25 | .init(Mon: "5月", value: 1200.0), 26 | .init(Mon: "6月", value: 1205.0), 27 | .init(Mon: "7月", value: 1100.0) 28 | ] 29 | 30 | struct chart_PointMark: View { 31 | var body: some View { 32 | VStack { 33 | if #available(iOS 16.0, *) { 34 | showPointMark 35 | } else { 36 | Text("Chart仅支持iOS 16.0") 37 | .font(.body) 38 | } 39 | } 40 | .navigationTitle("PointMark - 散点图") 41 | .navigationBarTitleDisplayMode(.inline) 42 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "PointMark")) 43 | } 44 | 45 | @available(iOS 16.0, *) 46 | var showPointMark: some View { 47 | GroupBox(label: Text("每月淘宝收入").padding(.vertical, 20)) { 48 | Chart(Salarys) { 49 | PointMark( 50 | x: .value("Mon", $0.Mon), 51 | y: .value("value", $0.value) 52 | ) 53 | } 54 | .frame(height: 250) 55 | .padding() 56 | } 57 | } 58 | } 59 | 60 | struct chart_PointMark_Previews: PreviewProvider { 61 | static var previews: some View { 62 | chart_PointMark() 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /hello/Components/toolbar/v_toolbar_bottomBar.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_toolbar_bottomBar.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/20/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_toolbar_bottomBar: View { 11 | 12 | var body: some View { 13 | VStack(alignment: .leading) { 14 | 15 | Text("注意页面底部工具栏,左右两侧图标。\n\n本页面示例 是对 toolbar placement: .bottomBar 的应用展示。 ") 16 | .font(.callout) 17 | .foregroundColor(.gray) 18 | .padding() 19 | .modifier(buttonViewCodeAndDocs(pageType: "SwiftUI",pageID: "toolbar_bottomBar")) 20 | Spacer() 21 | 22 | Text("") 23 | .toolbar { 24 | ToolbarItemGroup(placement: .bottomBar) { 25 | Button(action: {}, label: { 26 | Label("Add", systemImage: "folder.badge.plus") 27 | .foregroundColor(.yellow) 28 | }) 29 | Spacer() 30 | Button(action: {}, label: { 31 | Label("Edit", systemImage: "square.and.pencil") 32 | .foregroundColor(.yellow) 33 | }) 34 | } 35 | } 36 | } 37 | } 38 | } 39 | 40 | struct v_toolbar_bottomBar_Previews: PreviewProvider { 41 | static var previews: some View { 42 | v_toolbar_bottomBar() 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /hello/Components/toolbar/v_toolbar_cancellationAction.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_toolbar_cancellationAction.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/20/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_toolbar_cancellationAction: View { 11 | 12 | var body: some View { 13 | VStack(alignment: .leading) { 14 | 15 | Text("注意页面顶部导航栏。\n\n本页面示例 是对 toolbar placement: .cancellationAction 的应用展示。") 16 | .font(.callout) 17 | .foregroundColor(.gray) 18 | .padding() 19 | .modifier(buttonViewCodeAndDocs(pageType: "SwiftUI",pageID: "toolbar_cancellationAction")) 20 | Spacer() 21 | 22 | Text("") 23 | .toolbar { 24 | ToolbarItemGroup(placement: .cancellationAction) { 25 | Button(action: {}, label: { 26 | Label("Add", systemImage: "folder.badge.plus") 27 | .foregroundColor(.yellow) 28 | }) 29 | Button(action: {}, label: { 30 | Label("Edit", systemImage: "square.and.pencil") 31 | .foregroundColor(.yellow) 32 | }) 33 | } 34 | } 35 | } 36 | } 37 | } 38 | 39 | struct v_toolbar_cancellationAction_Previews: PreviewProvider { 40 | static var previews: some View { 41 | v_toolbar_cancellationAction() 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /hello/Components/toolbar/v_toolbar_destructiveAction.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_toolbar_destructiveAction.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/20/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_toolbar_destructiveAction: View { 11 | 12 | var body: some View { 13 | VStack(alignment: .leading) { 14 | 15 | Text("注意页面顶部导航栏。\n\n本页面示例 是对 toolbar placement: .destructiveAction 的应用展示。") 16 | .font(.callout) 17 | .foregroundColor(.gray) 18 | .padding() 19 | .modifier(buttonViewCodeAndDocs(pageType: "SwiftUI",pageID: "toolbar_destructiveAction")) 20 | Spacer() 21 | 22 | Text("") 23 | .toolbar { 24 | ToolbarItemGroup(placement: .destructiveAction) { 25 | Button(action: {}, label: { 26 | Label("Add", systemImage: "folder.badge.plus") 27 | .foregroundColor(.yellow) 28 | }) 29 | Button(action: {}, label: { 30 | Label("Edit", systemImage: "square.and.pencil") 31 | .foregroundColor(.yellow) 32 | }) 33 | } 34 | } 35 | } 36 | } 37 | } 38 | 39 | struct v_toolbar_destructiveAction_Previews: PreviewProvider { 40 | static var previews: some View { 41 | v_toolbar_destructiveAction() 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /hello/Components/toolbar/v_toolbar_keyboard.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_toolbar_keyboard.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/20/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_toolbar_keyboard: View { 11 | @State var text: String = "" 12 | @State var fontType: Font = .body 13 | 14 | var body: some View { 15 | VStack(alignment: .leading) { 16 | 17 | Text("请将光标置于输入框中,然后查看键盘。\n\n本页面示例 是对 toolbar placement: .keyboard 的应用展示。") 18 | .font(.callout) 19 | .foregroundColor(.gray) 20 | .padding() 21 | .modifier(buttonViewCodeAndDocs(pageType: "SwiftUI", pageID: "toolbar_keyboard")) 22 | 23 | TextEditor(text: $text) 24 | .frame(height: 150) 25 | .font(fontType) 26 | .padding() 27 | .overlay( 28 | RoundedRectangle(cornerRadius: 8) 29 | .stroke(Color.secondary, lineWidth: 1) 30 | ) 31 | .toolbar { 32 | ToolbarItemGroup(placement: .keyboard) { 33 | Button("加粗") { fontType = .body.bold() } 34 | Button("斜体") { fontType = .body.italic() } 35 | Spacer() 36 | } 37 | } 38 | 39 | Spacer() 40 | } 41 | } 42 | } 43 | 44 | struct v_toolbar_keyboard_Previews: PreviewProvider { 45 | static var previews: some View { 46 | v_toolbar_keyboard() 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /hello/Components/toolbar/v_toolbar_navigation.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_toolbar_navigation.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/20/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_toolbar_navigation: View { 11 | 12 | var body: some View { 13 | VStack(alignment: .leading) { 14 | 15 | Text("注意查看页面顶部导航栏尾部。\n\n本页面示例 是对 toolbar placement: .navigation 的应用展示。") 16 | .font(.callout) 17 | .foregroundColor(.gray) 18 | .padding() 19 | .modifier(buttonViewCodeAndDocs(pageType: "SwiftUI",pageID: "toolbar_navigation")) 20 | Spacer() 21 | 22 | Text("") 23 | .toolbar { 24 | ToolbarItemGroup(placement: .navigation) { 25 | Button(action: {}, label: { 26 | Label("Add", systemImage: "folder.badge.plus") 27 | .foregroundColor(.yellow) 28 | }) 29 | Spacer() 30 | Button(action: {}, label: { 31 | Label("Edit", systemImage: "square.and.pencil") 32 | .foregroundColor(.yellow) 33 | }) 34 | } 35 | } 36 | } 37 | } 38 | } 39 | 40 | struct v_toolbar_navigation_Previews: PreviewProvider { 41 | static var previews: some View { 42 | v_toolbar_navigation() 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /hello/Components/toolbar/v_toolbar_navigationBarLeading.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_toolbar_navigationBarLeading.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/20/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_toolbar_navigationBarLeading: View { 11 | 12 | var body: some View { 13 | VStack(alignment: .leading) { 14 | 15 | Text("注意页面顶部导航栏前缘部分。\n\n本页面示例 是对 toolbar placement: .navigationBarLeading 的应用展示。") 16 | .font(.callout) 17 | .foregroundColor(.gray) 18 | .padding() 19 | .modifier(buttonViewCodeAndDocs(pageType: "SwiftUI",pageID: "toolbar_navigationBarLeading")) 20 | Spacer() 21 | 22 | Text("") 23 | .toolbar { 24 | ToolbarItemGroup(placement: .navigationBarLeading) { 25 | Button(action: {}, label: { 26 | Label("Add", systemImage: "folder.badge.plus") 27 | .foregroundColor(.yellow) 28 | }) 29 | Spacer() 30 | Button(action: {}, label: { 31 | Label("Edit", systemImage: "square.and.pencil") 32 | .foregroundColor(.yellow) 33 | }) 34 | } 35 | } 36 | } 37 | } 38 | } 39 | 40 | struct v_toolbar_navigationBarLeading_Previews: PreviewProvider { 41 | static var previews: some View { 42 | v_toolbar_navigationBarLeading() 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /hello/Components/toolbar/v_toolbar_navigationBarTrailing.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_toolbar_navigationBarTrailing.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/20/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_toolbar_navigationBarTrailing: View { 11 | 12 | var body: some View { 13 | VStack(alignment: .leading) { 14 | 15 | Text("注意查看页面顶部导航栏尾部。\n\n本页面示例 是对 toolbar placement: .navigationBarTrailing 的应用展示。") 16 | .font(.callout) 17 | .foregroundColor(.gray) 18 | .padding() 19 | .modifier(buttonViewCodeAndDocs(pageType: "SwiftUI", pageID: "toolbar_navigationBarTrailing")) 20 | Spacer() 21 | 22 | Text("") 23 | .toolbar { 24 | ToolbarItemGroup(placement: .navigationBarTrailing) { 25 | Button(action: {}, label: { 26 | Label("Add", systemImage: "folder.badge.plus") 27 | .foregroundColor(.yellow) 28 | }) 29 | Spacer() 30 | Button(action: {}, label: { 31 | Label("Edit", systemImage: "square.and.pencil") 32 | .foregroundColor(.yellow) 33 | }) 34 | } 35 | } 36 | } 37 | } 38 | } 39 | 40 | struct v_toolbar_navigationBarTrailing_Previews: PreviewProvider { 41 | static var previews: some View { 42 | v_toolbar_navigationBarTrailing() 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /hello/Components/toolbar/v_toolbar_principal.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_toolbar_principal.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/20/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | fileprivate var pageDesc:String = """ 11 | 注意页面顶部,中间部分。 12 | 13 | 本页面示例,是对 toolbar ToolbarItemGroup(placement: .principal) 的展示。 14 | 15 | 在 iOS、iPadOS 和 tvOS 中,系统将主要项目放置在导航栏的中心。此项目优先于通过 指定的标题。View/navigationTitle" 16 | """ 17 | 18 | struct v_toolbar_principal: View { 19 | 20 | var body: some View { 21 | VStack(alignment: .leading) { 22 | 23 | Text(pageDesc) 24 | .font(.callout) 25 | .foregroundColor(.gray) 26 | .padding() 27 | .modifier(buttonViewCodeAndDocs(pageType: "SwiftUI", pageID: "toolbar_principal")) 28 | Spacer() 29 | 30 | Text("") 31 | .toolbar { 32 | ToolbarItemGroup(placement: .principal) { 33 | HStack { 34 | Text("同城") 35 | Text("关注") 36 | Text("搜索") 37 | } 38 | } 39 | } 40 | } 41 | } 42 | } 43 | 44 | struct v_toolbar_principal_Previews: PreviewProvider { 45 | static var previews: some View { 46 | v_toolbar_principal() 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /hello/Components/toolbar/v_toolbar_secondaryAction.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_toolbar_secondaryAction.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/20/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | fileprivate let pageDesc:String = """ 11 | 注意页面顶部导航栏尾部。 12 | 13 | 本页面示例 是对 toolbar placement: .secondaryAction 的应用展示。 14 | 15 | .secondaryAction 是iOS 16.0新增的方法,只有手机系统为iOS 16.0+时,才能看到效果 16 | """ 17 | 18 | struct v_toolbar_secondaryAction: View { 19 | 20 | var body: some View { 21 | VStack(alignment: .leading) { 22 | 23 | Text(pageDesc) 24 | .font(.callout) 25 | .foregroundColor(.gray) 26 | .padding() 27 | .modifier(buttonViewCodeAndDocs(pageType: "SwiftUI",pageID: "toolbar_secondaryAction")) 28 | Spacer() 29 | 30 | if #available(iOS 16.0, *) { 31 | Text("") 32 | .toolbar { 33 | ToolbarItemGroup(placement: .secondaryAction) { 34 | Button(action: {}, label: { 35 | Label("Add", systemImage: "folder.badge.plus") 36 | .foregroundColor(.yellow) 37 | }) 38 | Button(action: {}, label: { 39 | Label("Edit", systemImage: "square.and.pencil") 40 | .foregroundColor(.yellow) 41 | }) 42 | } 43 | } 44 | } 45 | } 46 | } 47 | } 48 | 49 | struct v_toolbar_secondaryAction_Previews: PreviewProvider { 50 | static var previews: some View { 51 | v_toolbar_secondaryAction() 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /hello/Components/toolbar/v_toolbar_status.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_toolbar_status.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/20/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_toolbar_status: View { 11 | 12 | var body: some View { 13 | VStack(alignment: .leading) { 14 | 15 | Text("注意页面底部中间位置。\n本页面示例 是对 toolbar placement: .status 的应用展示。") 16 | .font(.callout) 17 | .foregroundColor(.gray) 18 | .padding() 19 | .modifier(buttonViewCodeAndDocs(pageType: "SwiftUI", pageID: "toolbar_status")) 20 | Spacer() 21 | 22 | Text("") 23 | .toolbar { 24 | ToolbarItemGroup(placement: .status) { 25 | Button(action: {}, label: { 26 | Label("Add", systemImage: "folder.badge.plus") 27 | .foregroundColor(.yellow) 28 | }) 29 | Spacer() 30 | Button(action: {}, label: { 31 | Label("Edit", systemImage: "square.and.pencil") 32 | .foregroundColor(.yellow) 33 | }) 34 | } 35 | } 36 | } 37 | } 38 | } 39 | 40 | struct v_toolbar_status_Previews: PreviewProvider { 41 | static var previews: some View { 42 | v_toolbar_status() 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /hello/Components/v_ActionSheet.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewActionSheet.swift 3 | // format 4 | // 5 | // Created by 1 on 7/29/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_ActionSheet: View { 11 | @State private var showActionSheet: Bool = false 12 | 13 | var body: some View { 14 | 15 | VStack { 16 | Text("简介:actionSheet iOS 13.0–16.0 Deprecated。iOS 15.0+,建议使用confirmationDialog") 17 | .font(.caption) 18 | .foregroundColor(.gray) 19 | .frame(height: 80) 20 | 21 | Button("点击显示 actionSheet") { 22 | showActionSheet = true 23 | } 24 | .actionSheet(isPresented: $showActionSheet) { 25 | ActionSheet( 26 | title: Text("请选择操作"), 27 | message: Text("xxxxxxxxxxx"), 28 | buttons: [ 29 | .cancel( 30 | Text("取消") 31 | ), 32 | .default( 33 | Text("确认") 34 | ) 35 | ] 36 | ) 37 | } 38 | } 39 | .padding() 40 | .navigationTitle("ActionSheet") 41 | .navigationBarTitleDisplayMode(.inline) 42 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "ActionSheet")) 43 | } 44 | } 45 | 46 | struct v_ActionSheet_Previews: PreviewProvider { 47 | static var previews: some View { 48 | v_ActionSheet() 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /hello/Components/v_Alert.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewAlert.swift 3 | // format 4 | // 5 | // Created by 1 on 7/29/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_Alert: View { 11 | @State var showingAlert1: Bool = false 12 | @State var showingAlert2: Bool = false 13 | 14 | var body: some View { 15 | 16 | VStack(spacing: 100) { 17 | 18 | // 样式1 19 | Button("Alert 弹窗样式1", action: { 20 | self.showingAlert1 = true 21 | }).alert(isPresented: $showingAlert1) { 22 | Alert( 23 | title: Text("标题1"), 24 | message: Text("这是消息内容"), 25 | dismissButton: .default(Text("OK")) 26 | ) 27 | } 28 | 29 | 30 | // 样式2 31 | Button("Alert 弹窗样式2", action: { 32 | self.showingAlert2 = true 33 | }).alert(isPresented: $showingAlert2) { 34 | Alert( 35 | title: Text("标题2"), 36 | message: Text("这是消息内容"), 37 | primaryButton: .default(Text("确定")), 38 | secondaryButton: .destructive(Text("取消")) 39 | ) 40 | } 41 | } 42 | .navigationTitle("Alert") 43 | .navigationBarTitleDisplayMode(.inline) 44 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "Alert")) 45 | } 46 | } 47 | 48 | struct v_Alert_Previews: PreviewProvider { 49 | static var previews: some View { 50 | v_Alert() 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /hello/Components/v_Canvas.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PagesCanvas.swift 3 | // format 4 | // 5 | // Created by 1 on 7/29/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_Canvas: View { 11 | var body: some View { 12 | VStack { 13 | Canvas { context, size in 14 | context.stroke( 15 | Path(ellipseIn: CGRect(origin: .zero, size: size)), 16 | with: .color(.green), 17 | lineWidth: 4) 18 | } 19 | .frame(width: 300, height: 200) 20 | .border(Color.blue) 21 | } 22 | .navigationTitle("Canvas") 23 | .navigationBarTitleDisplayMode(.inline) 24 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "Canvas")) 25 | } 26 | } 27 | 28 | struct v_Canvas_Previews: PreviewProvider { 29 | static var previews: some View { 30 | v_Canvas() 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /hello/Components/v_DisclosureGroup.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_DisclosureGroup.swift 3 | // format 4 | // 5 | // Created by 1 on 7/28/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | @available (iOS 14.0, *) 11 | struct v_DisclosureGroup: View { 12 | struct ToggleStates { 13 | var oneIsOn: Bool = false 14 | var twoIsOn: Bool = true 15 | } 16 | @State private var toggleStates = ToggleStates() 17 | @State private var topExpanded: Bool = true 18 | 19 | var body: some View { 20 | VStack { 21 | DisclosureGroup("Items", isExpanded: $topExpanded) { 22 | Toggle("Toggle 1", isOn: $toggleStates.oneIsOn) 23 | Toggle("Toggle 2", isOn: $toggleStates.twoIsOn) 24 | DisclosureGroup("Sub-items") { 25 | Text("Sub-item 1") 26 | } 27 | } 28 | } 29 | .navigationTitle("DisclosureGroup") 30 | .navigationBarTitleDisplayMode(.inline) 31 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "DisclosureGroup")) 32 | } 33 | } 34 | 35 | struct v_DisclosureGroup_Previews: PreviewProvider { 36 | static var previews: some View { 37 | v_DisclosureGroup() 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /hello/Components/v_Divider.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_Divider.swift 3 | // format 4 | // 5 | // Created by 1 on 7/29/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_Divider: View { 11 | var body: some View { 12 | VStack { 13 | Text("标题") 14 | .font(.title) 15 | 16 | Divider() 17 | 18 | Text("如上所示,分割线 即为 Divider() 效果。") 19 | .font(.caption) 20 | .foregroundColor(.gray) 21 | .frame(height: 80) 22 | } 23 | .padding() 24 | .navigationTitle("Divider") 25 | .navigationBarTitleDisplayMode(.inline) 26 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "Divider")) 27 | } 28 | } 29 | 30 | struct v_Divider_Previews: PreviewProvider { 31 | static var previews: some View { 32 | v_Divider() 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /hello/Components/v_Form.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_Form.swift 3 | // format 4 | // 5 | // Created by 1 on 7/28/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_Form: View { 11 | @State private var username: String = "" 12 | @State private var password: String = "" 13 | @State private var isRemember: Bool = false 14 | 15 | var body: some View { 16 | VStack { 17 | Form { 18 | Section() { 19 | TextField("username", text: $username) 20 | 21 | SecureField("password", text: $password) 22 | 23 | Toggle("是否记住密码", isOn: $isRemember) 24 | } 25 | 26 | Button("登录", action: { 27 | print("您输入的内容:\(username) \(password)") 28 | }) 29 | .frame(alignment: .center) 30 | } 31 | } 32 | .navigationTitle("Form") 33 | .navigationBarTitleDisplayMode(.inline) 34 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "Form")) 35 | } 36 | } 37 | 38 | struct v_Form_Previews: PreviewProvider { 39 | static var previews: some View { 40 | v_Form() 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /hello/Components/v_Gesture.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_Gesture.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 7/31/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_Gesture: View { 11 | var body: some View { 12 | VStack { 13 | List { 14 | Section("点击") { 15 | NavigationLink(".onTapGesture() - 点击", destination: v_onTapGesture()) 16 | NavigationLink(destination: v_SpatialTapGesture(), label: { 17 | Text("SpatialTapGesture") 18 | Text("iOS 16.0+") 19 | .font(.caption) 20 | .foregroundColor(.secondary) 21 | }) 22 | } 23 | 24 | Section("长按") { 25 | NavigationLink(".onLongPressGesture()", destination: v_onLongPressGesture()) 26 | NavigationLink(".gesture( LongPressGesture() )", destination: v_gesture_LongPressGesture()) 27 | } 28 | 29 | Section("") { 30 | NavigationLink("DragGesture() - 拖拽", destination: v_DragGesture()) 31 | NavigationLink("MagnificationGesture() - 缩放", destination: v_MagnificationGesture()) 32 | NavigationLink("RotationGesture() - 旋转", destination: v_RotationGesture()) 33 | } 34 | } 35 | } 36 | .navigationTitle("Gesture - 手势") 37 | .navigationBarTitleDisplayMode(.inline) 38 | } 39 | } 40 | 41 | struct v_Gesture_Previews: PreviewProvider { 42 | static var previews: some View { 43 | v_Gesture() 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /hello/Components/v_Grid.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_Grid.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 8/3/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_Grid: View { 11 | 12 | var body: some View { 13 | Text("SwiftUI Gird 仅支持iOS 16.0") 14 | .font(.body) 15 | 16 | if #available(iOS 16.0, *) { 17 | ShowGrid 18 | } 19 | } 20 | 21 | @available(iOS 16.0, *) 22 | var ShowGrid: some View { 23 | Grid(alignment: .bottom, horizontalSpacing: 1, verticalSpacing: 1) { 24 | GridRow { 25 | Text("Row 1") 26 | ForEach(0..<2) { _ in Color.red } 27 | } 28 | GridRow { 29 | Text("Row 2") 30 | ForEach(0..<5) { _ in Color.green } 31 | } 32 | GridRow { 33 | Text("Row 3") 34 | ForEach(0..<4) { _ in Color.blue } 35 | } 36 | } 37 | .frame(height: 200) 38 | .padding() 39 | .navigationTitle("Grid") 40 | .navigationBarTitleDisplayMode(.inline) 41 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "Grid")) 42 | } 43 | } 44 | 45 | struct v_Grid_Previews: PreviewProvider { 46 | static var previews: some View { 47 | v_Grid() 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /hello/Components/v_Group.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_Group.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/22/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_Group: View { 11 | var body: some View { 12 | VStack(alignment: .leading) { 13 | Text("Group 用于将实例(视图等),收集到一组或一个单元中。如下示例, Group 包含了3个 Text , 对 Group 设置 .font() 后,所有Text样式都被改变。") 14 | .font(.callout) 15 | .foregroundColor(.gray) 16 | .frame(height: 90) 17 | 18 | Group { 19 | Text("SwiftUI") 20 | Text("Combine") 21 | Text("Swift System") 22 | } 23 | .font(.headline) 24 | 25 | Spacer() 26 | } 27 | .padding() 28 | .navigationTitle("Group") 29 | .navigationBarTitleDisplayMode(.inline) 30 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "Group")) 31 | } 32 | 33 | } 34 | 35 | struct v_Group_Previews: PreviewProvider { 36 | static var previews: some View { 37 | v_Group() 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /hello/Components/v_GroupBox.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_GroupBox.swift 3 | // format 4 | // 5 | // Created by 1 on 7/28/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_GroupBox: View { 11 | @State private var isAgreed: Bool = true 12 | @State private var bodyContent: String = """ 13 | 在此特别提醒您(用户)在注册成为用户之前,请认真阅读本《隐私协议》(以下简称“协议”),确保您充分理解本协议中各条款。请您审慎阅读并选择接受或不接受本协议。您的注册、登录、使用等行为将视为对本协议的接受,并同意接受本协议各项条款的约束。本协议约定 我司与用户之间关于软件或服务的权利义务。“用户”是指注册、登录、使用本服务的个人。本协议可由本公司随时更新,更新后的协议条款一旦公布即代替原来的协议条款,恕不再另行通知,用户可在本公司产品中查阅最新版协议条款。在修改协议条款后,如果用户不接受修改后的条款,请立即停止使用本公司提供的服务,用户继续使用服务将被视为接受修改后的协议。 14 | """ 15 | 16 | var body: some View { 17 | VStack { 18 | GroupBox(label: 19 | Label("隐私协议", systemImage: "building.columns") 20 | ) { 21 | ScrollView(.vertical, showsIndicators: true) { 22 | Text(bodyContent) 23 | .font(.footnote) 24 | } 25 | .frame(height: 200) 26 | Toggle(isOn: $isAgreed) { 27 | Text("我同意") 28 | } 29 | } 30 | } 31 | .navigationTitle("GroupBox") 32 | .navigationBarTitleDisplayMode(.inline) 33 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "GroupBox")) 34 | } 35 | } 36 | 37 | struct v_GroupBox_Previews: PreviewProvider { 38 | static var previews: some View { 39 | v_GroupBox() 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /hello/Components/v_Image.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewImage.swift 3 | // format 4 | // 5 | // Created by 1 on 7/29/22. 6 | // update by 1 on 2022-08-23 7 | // 8 | 9 | import SwiftUI 10 | 11 | struct v_Image: View { 12 | 13 | @State private var selectedTab: Int = 0 14 | 15 | var body: some View { 16 | VStack { 17 | List { 18 | NavigationLink("SF符号", destination: v_image_SF()) 19 | NavigationLink("Assets图片", destination: v_image_local()) 20 | NavigationLink("使用URLSession下载图片", destination: v_image_URLSession()) 21 | NavigationLink("使用AsyncImage下载图片", destination: v_image_AsyncImage()) 22 | } 23 | } 24 | .navigationTitle("Image") 25 | .navigationBarTitleDisplayMode(.inline) 26 | } 27 | } 28 | 29 | // 使用Bundle方式加载图片 30 | struct UseBundleImageView: View { 31 | var body: some View { 32 | Group { 33 | if let resBundlePath = Bundle.main.path(forResource: "Resources", ofType: "bundle"), 34 | let resBundle = Bundle(path: resBundlePath), 35 | let uiImage = UIImage(named: "2022.jpeg", in: resBundle, with: nil){ 36 | Image(uiImage: uiImage) 37 | .resizable() 38 | .scaledToFit() 39 | .frame(width: 20, height: 20, alignment: .center) 40 | .clipped() 41 | } else { 42 | Color.red 43 | } 44 | } 45 | } 46 | } 47 | 48 | struct v_Image_Previews: PreviewProvider { 49 | static var previews: some View { 50 | v_Image() 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /hello/Components/v_Label.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_Label.swift 3 | // format 4 | // 5 | // Created by 1 on 7/27/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_Label: View { 11 | var body: some View { 12 | VStack(alignment: .center, spacing: 30) { 13 | 14 | Section(header: Text("默认语法,文本 + 图标").textCallout()) { 15 | Label("Lightning", systemImage: "bolt.fill") 16 | 17 | Label("Lightning", systemImage: "cloud.bolt.fill") 18 | .labelStyle(.titleAndIcon) 19 | } 20 | 21 | Section(header: Text(".iconOnly 仅显示图标").textCallout()) { 22 | HStack(spacing: 20) { 23 | Label("Rain", systemImage: "cloud.rain") 24 | Label("Snow", systemImage: "snow") 25 | } 26 | .labelStyle(.iconOnly) 27 | } 28 | } 29 | .navigationTitle("Label") 30 | .navigationBarTitleDisplayMode(.inline) 31 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "Label")) 32 | } 33 | } 34 | 35 | struct v_Label_Previews: PreviewProvider { 36 | static var previews: some View { 37 | v_Label() 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /hello/Components/v_LabeledContent.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_LabeledContent.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/10/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_LabeledContent: View { 11 | var body: some View { 12 | VStack(alignment: .leading) { 13 | Text("LabeledContent, 仅适用于iOS 16.0+。示例效果如下:") 14 | .font(.footnote) 15 | .padding() 16 | 17 | if #available(iOS 16.0, *) { 18 | exampleForLabeledContent 19 | } 20 | 21 | Spacer() 22 | } 23 | .navigationTitle("LabeledContent") 24 | .navigationBarTitleDisplayMode(.inline) 25 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "LabeledContent")) 26 | 27 | } 28 | 29 | @available (iOS 16.0, *) 30 | var exampleForLabeledContent: some View { 31 | Form { 32 | // 示例1 33 | LabeledContent("Label", value: "Content") 34 | 35 | // 示例2 36 | LabeledContent { 37 | EmptyView() 38 | } label: { 39 | Text("Custom Value") 40 | } 41 | 42 | // 示例3 43 | LabeledContent("Number", value: 100.0, format: .number.precision(.fractionLength(0)) ) 44 | } 45 | .frame(height: 200) 46 | } 47 | } 48 | 49 | struct v_LabeledContent_Previews: PreviewProvider { 50 | static var previews: some View { 51 | v_LabeledContent() 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /hello/Components/v_Link.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewLink.swift 3 | // format 4 | // 5 | // Created by 1 on 7/28/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_Link: View { 11 | 12 | var body: some View { 13 | 14 | VStack(spacing: 20) { 15 | Link("Link示例:点击apple.com在浏览器打开", 16 | destination: URL(string: "https://www.apple.com")!) 17 | 18 | Divider() 19 | 20 | Link("Link示例:Visit Our Site", destination: URL(string: "https://www.example.com")!) 21 | .environment(\.openURL, OpenURLAction { url in 22 | print("您点击的URL是: \(url)") 23 | return .handled 24 | }) 25 | 26 | Divider() 27 | 28 | if #available(iOS 16.0, *) { 29 | ShareLink(item: URL(string: "https://developer.apple.com/xcode/swiftui/")!) { 30 | Label("ShareLink示例", image: "square.and.arrow.up") 31 | } 32 | } 33 | } 34 | .navigationTitle("Link") 35 | .navigationBarTitleDisplayMode(.inline) 36 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "Link")) 37 | } 38 | } 39 | 40 | struct v_Link_Previews: PreviewProvider { 41 | static var previews: some View { 42 | v_Link() 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /hello/Components/v_Maps.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PagesMaps.swift 3 | // format 4 | // 5 | // Created by 1 on 7/29/22. 6 | // 7 | 8 | import SwiftUI 9 | import MapKit 10 | 11 | struct v_Maps: View { 12 | @State var region: MKCoordinateRegion = MKCoordinateRegion( 13 | center: CLLocationCoordinate2DMake(37.8, 117.5), 14 | latitudinalMeters: 5000, 15 | longitudinalMeters: 5000 16 | ) 17 | 18 | var body: some View { 19 | VStack { 20 | Text("地图控件") 21 | .font(.title) 22 | 23 | Map(coordinateRegion: $region) 24 | .frame(height: 300) 25 | } 26 | .navigationTitle("Map") 27 | .navigationBarTitleDisplayMode(.inline) 28 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "Map")) 29 | } 30 | } 31 | 32 | struct v_Maps_Previews: PreviewProvider { 33 | static var previews: some View { 34 | v_Maps() 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /hello/Components/v_Menu.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_Menu.swift 3 | // format 4 | // 5 | // Created by 1 on 7/24/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_Menu: View { 11 | var body: some View { 12 | VStack { 13 | 14 | Menu { 15 | Button(action: addCurrentTabToReadingList) { 16 | Label("添加列表", systemImage: "eyeglasses") 17 | } 18 | Button(action: bookmarkAll) { 19 | Label("添加书签", systemImage: "book") 20 | } 21 | Button(action: show) { 22 | Label("显示所有书签", systemImage: "books.vertical") 23 | } 24 | Menu("二级菜单") { 25 | Button("Share", action: share) 26 | } 27 | } label: { 28 | Label("Menu示例", systemImage: "menucard") 29 | } primaryAction: { 30 | addBookmark() 31 | } 32 | .font(.title3) 33 | 34 | Text("说明:长按以上内容,即可看到菜单列表。iOS 16.0,新增了.menuOrder() 可以设置首选项顺序") 35 | .font(.caption) 36 | .foregroundColor(.gray) 37 | .padding(EdgeInsets(top: 50, leading: 10, bottom: 0, trailing: 10)) 38 | } 39 | .navigationTitle("Menu") 40 | .navigationBarTitleDisplayMode(.inline) 41 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "Menu")) 42 | } 43 | 44 | 45 | func addCurrentTabToReadingList() {} 46 | 47 | func addBookmark() {} 48 | 49 | func bookmarkAll() {} 50 | 51 | func show() {} 52 | 53 | func share() {} 54 | } 55 | 56 | struct v_Menu_Previews: PreviewProvider { 57 | static var previews: some View { 58 | v_Menu() 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /hello/Components/v_Navigation.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_Navigation.swift 3 | // format 4 | // 5 | // Created by 1 on 7/29/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_Navigation: View { 11 | 12 | var body: some View { 13 | VStack(spacing: 30) { 14 | 15 | NavigationLink("跳转到Map页面", destination: v_Maps()) 16 | 17 | NavigationLink(destination: v_Image()){ 18 | Label("跳转到Image页面", systemImage: "photo") 19 | } 20 | } 21 | .navigationTitle("NavigationLink") 22 | .navigationBarTitleDisplayMode(.inline) 23 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "NavigationLink")) 24 | } 25 | } 26 | 27 | struct v_Navigation_Previews: PreviewProvider { 28 | static var previews: some View { 29 | v_Navigation() 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /hello/Components/v_NavigationStack.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_NavigationStack.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/24/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_NavigationStack: View { 11 | 12 | var body: some View { 13 | VStack(alignment: .leading, spacing: 20) { 14 | Text("在App内,对NavigationStack,呈现肉眼可观察的效果,并不容易(因为App本身就使用了NavigationStack,在此页面使用会导致闪退)。") 15 | 16 | Text("对于NavigationStack,建议直接观看官方文档。") 17 | 18 | NavigationLink("NavigationStack 文档", destination: { 19 | loadOpenUrl(url: "https://developer.apple.com/documentation/swiftui/NavigationStack") 20 | }) 21 | 22 | Text("右上角【示例源码】,对于NavigationStack的用法,写了一个简单的demo。请新建一个项目,拷贝源码,直接查看。") 23 | .font(.headline) 24 | 25 | Spacer() 26 | } 27 | .padding() 28 | .navigationTitle("NavigationStack") 29 | .navigationBarTitleDisplayMode(.inline) 30 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "NavigationStack")) 31 | } 32 | } 33 | 34 | struct v_NavigationStack_Previews: PreviewProvider { 35 | static var previews: some View { 36 | v_NavigationStack() 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /hello/Components/v_NavigationView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_NavigationView.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/24/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | 11 | struct v_NavigationView: View { 12 | 13 | var body: some View { 14 | VStack(alignment: .leading, spacing: 20) { 15 | Text("在App内,对NavigationView,呈现肉眼可观察的效果,并不容易。对于NavigationView,建议直接观看官方文档。") 16 | 17 | Text("另外,NavigationView本身限制颇多,一些基本功能,比如返回根视图、向堆栈添加任意视图、返回任意层级视图,这些NavigationView本身无法实现。") 18 | 19 | Text("iOS 16.0+, 建议直接使用NavigationStack") 20 | 21 | NavigationLink("navigationview 文档", destination: { 22 | loadOpenUrl(url: "https://developer.apple.com/documentation/swiftui/navigationview") 23 | }) 24 | 25 | Spacer() 26 | } 27 | .padding() 28 | .navigationTitle("NavigationView") 29 | .navigationBarTitleDisplayMode(.inline) 30 | } 31 | } 32 | 33 | struct v_NavigationView_Previews: PreviewProvider { 34 | static var previews: some View { 35 | v_NavigationView() 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /hello/Components/v_PasteButton.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_PasteButton.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/3/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | 11 | struct v_PasteButton: View { 12 | @State private var username = "小明同学" 13 | 14 | init() { 15 | UITextView.appearance().backgroundColor = .clear 16 | } 17 | 18 | var body: some View { 19 | VStack(alignment: .leading) { 20 | Text("说明:PasteButton 适用于iOS 16.0+。PasteButton会接收符合Transferable协议的任何类型的数据,例如String和Data。") 21 | .font(.caption) 22 | .foregroundColor(.gray) 23 | .frame(height: 80) 24 | 25 | TextEditor(text: $username) 26 | .frame(height: 200) 27 | .cornerRadius(3.0) 28 | 29 | 30 | if #available (iOS 16.0, *) { 31 | PasteButton(payloadType: String.self) { strings in 32 | guard let first = strings.first else { return } 33 | username = first 34 | } 35 | .buttonBorderShape(.capsule) 36 | } 37 | 38 | Spacer() 39 | } 40 | .padding() 41 | .frame(maxHeight: .infinity) 42 | .background(.gray.opacity(0.1)) 43 | .navigationTitle("PasteButton") 44 | .navigationBarTitleDisplayMode(.inline) 45 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "PasteButton")) 46 | } 47 | } 48 | 49 | struct v_PasteButton_Previews: PreviewProvider { 50 | static var previews: some View { 51 | v_PasteButton() 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /hello/Components/v_Picker.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewPicker.swift 3 | // format 4 | // 5 | // Created by 1 on 7/28/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_Picker: View { 11 | 12 | var body: some View { 13 | VStack { 14 | List { 15 | 16 | Section("Picker样式") { 17 | NavigationLink("默认样式", destination: v_pickerStyle_default()) 18 | NavigationLink("menu样式", destination: v_pickerStyle_menu()) 19 | NavigationLink("segmented样式", destination: v_pickerStyle_segmented()) 20 | NavigationLink("wheel样式", destination: v_pickerStyle_wheel()) 21 | NavigationLink("inline样式", destination: v_pickerStyle_inline()) 22 | } 23 | 24 | Section(header: Text("多列选择器")) { 25 | NavigationLink("选择省市", destination: v_MultiPicker()) 26 | } 27 | 28 | Section(header: Text("ColorPicker").textCase(.none)) { 29 | NavigationLink("颜色选择器", destination: v_ColorPicker()) 30 | } 31 | 32 | Section(header: Text("DatePicker").textCase(.none)) { 33 | NavigationLink("日期选择器", destination: v_DatePicker()) 34 | } 35 | } 36 | } 37 | .navigationTitle("Picker") 38 | .navigationBarTitleDisplayMode(.inline) 39 | } 40 | } 41 | 42 | 43 | struct v_Picker_Previews: PreviewProvider { 44 | static var previews: some View { 45 | v_Picker() 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /hello/Components/v_Popover.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_popover.swift 3 | // format 4 | // 5 | // Created by 1 on 7/30/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_Popover: View { 11 | @State var isShowPopover: Bool = false 12 | 13 | var body: some View { 14 | VStack { 15 | Button("Click Show Popover", action: { 16 | self.isShowPopover.toggle() 17 | }) 18 | .popover(isPresented: $isShowPopover) { 19 | Text("本窗口由.popover弹出") 20 | } 21 | } 22 | .navigationTitle(".popover") 23 | .navigationBarTitleDisplayMode(.inline) 24 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "popover")) 25 | } 26 | } 27 | 28 | struct v_Popover_Previews: PreviewProvider { 29 | static var previews: some View { 30 | v_Popover() 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /hello/Components/v_ProgressView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewProgressView.swift 3 | // format 4 | // 5 | // Created by 1 on 7/29/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_ProgressView: View { 11 | @State private var progress = 0.5 12 | 13 | var body: some View { 14 | VStack(spacing: 30) { 15 | Section() { 16 | Text("进度条样式") 17 | .font(.title3) 18 | 19 | ProgressView(value: progress) 20 | 21 | Button("More", action: { progress += 0.05 }) 22 | .padding() 23 | } 24 | 25 | Divider() 26 | 27 | Section() { 28 | Text("loading样式") 29 | .font(.title3) 30 | 31 | ProgressView(value: progress) 32 | .progressViewStyle(.circular) 33 | } 34 | } 35 | .padding() 36 | .navigationTitle("ProgressView") 37 | .navigationBarTitleDisplayMode(.inline) 38 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "ProgressView")) 39 | } 40 | } 41 | 42 | struct DarkBlueShadowProgressViewStyle: ProgressViewStyle { 43 | func makeBody(configuration: Configuration) -> some View { 44 | ProgressView(configuration) 45 | .shadow(color: Color(red: 0, green: 0, blue: 0.6), 46 | radius: 4.0, x: 1.0, y: 2.0) 47 | } 48 | } 49 | 50 | struct v_ProgressView_Previews: PreviewProvider { 51 | static var previews: some View { 52 | v_ProgressView() 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /hello/Components/v_ScrollView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewScrollView.swift 3 | // format 4 | // 5 | // Created by 1 on 7/29/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_ScrollView: View { 11 | var body: some View { 12 | List { 13 | Section() { 14 | NavigationLink("纵向滚动", destination: v_ScrollView_vertical()) 15 | } 16 | 17 | Section() { 18 | NavigationLink("水平滚动", destination: v_ScrollView_horizontal()) 19 | } 20 | } 21 | } 22 | } 23 | 24 | struct v_ScrollView_Previews: PreviewProvider { 25 | static var previews: some View { 26 | v_ScrollView() 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /hello/Components/v_ScrollView_horizontal.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_ScrollView_horizontal.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/26/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_ScrollView_horizontal: View { 11 | var body: some View { 12 | ScrollView(.horizontal, showsIndicators: false) { 13 | HStack(spacing: 16) { 14 | ForEach(0 ..< 5) { item in 15 | RoundedRectangle(cornerRadius: 30) 16 | .fill(.blue) 17 | .frame(width: 250, height: 200) 18 | } 19 | } 20 | .padding() 21 | } 22 | .navigationTitle("ScrollView") 23 | .navigationBarTitleDisplayMode(.inline) 24 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "ScrollView_horizontal")) 25 | } 26 | } 27 | 28 | struct v_ScrollView_horizontal_Previews: PreviewProvider { 29 | static var previews: some View { 30 | v_ScrollView_horizontal() 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /hello/Components/v_ScrollView_vertical.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_ScrollView_vertical.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/26/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_ScrollView_vertical: View { 11 | var body: some View { 12 | ScrollView(.vertical, showsIndicators: false) { 13 | VStack(spacing: 20) { 14 | ForEach(0 ..< 20) { item in 15 | RoundedRectangle(cornerRadius: 30) 16 | .fill(.white) 17 | .frame(height: 150) 18 | .overlay( 19 | Text("图形 - \(item)") 20 | ) 21 | } 22 | } 23 | .padding() 24 | .frame(maxWidth: .infinity) 25 | .backgroundColor(.gray.opacity(0.2)) 26 | } 27 | .ignoresSafeArea(edges: .bottom) 28 | .navigationTitle("ScrollView") 29 | .navigationBarTitleDisplayMode(.inline) 30 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "ScrollView_vertical")) 31 | } 32 | } 33 | 34 | struct v_ScrollView_vertical_Previews: PreviewProvider { 35 | static var previews: some View { 36 | v_ScrollView_vertical() 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /hello/Components/v_Sheet.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewSheet.swift 3 | // format 4 | // 5 | // Created by 1 on 7/28/22. 6 | // 7 | 8 | 9 | import SwiftUI 10 | 11 | @available (iOS 13.0, *) 12 | struct v_Sheet: View { 13 | @State private var sheetShown = false 14 | @State private var query = "" 15 | 16 | var body: some View { 17 | VStack() { 18 | 19 | Show_SwiftUI_Docs(available_versions: ui_sheet_available_versions, desc: ui_sheet_desc, declaration: ui_sheet_declaration) 20 | 21 | Button("点击显示底部sheet") { 22 | sheetShown = true 23 | } 24 | .buttonStyle(.bordered) 25 | .sheet(isPresented: $sheetShown) { 26 | NavigationView { 27 | Text("You query: \(query)") 28 | .searchable(text: $query) 29 | .navigationTitle("Search") 30 | } 31 | // iOS 16.0 增加.presentationDetents() 修饰符,可以控制sheet大小 32 | // .presentationDetents([.medium]) 33 | } 34 | 35 | Spacer() 36 | } 37 | .navigationTitle(".sheet") 38 | .navigationBarTitleDisplayMode(.inline) 39 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "sheet")) 40 | } 41 | } 42 | 43 | struct v_Sheet_Previews: PreviewProvider { 44 | static var previews: some View { 45 | v_Sheet() 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /hello/Components/v_Spacer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_Spacer.swift 3 | // format 4 | // 5 | // Created by 1 on 7/29/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_Spacer: View { 11 | 12 | var body: some View { 13 | VStack { 14 | 15 | Text("Spacer()效果") 16 | .font(.callout) 17 | 18 | HStack { 19 | Image(systemName: "checkmark") 20 | Spacer() 21 | Text("Test") 22 | } 23 | .border(.gray.opacity(0.1)) 24 | .padding(.vertical, 50) 25 | 26 | } 27 | .navigationTitle("Spacer()") 28 | .navigationBarTitleDisplayMode(.inline) 29 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "Spacer")) 30 | } 31 | } 32 | 33 | struct v_Spacer_Previews: PreviewProvider { 34 | static var previews: some View { 35 | v_Spacer() 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /hello/Components/v_Stepper.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewStepper.swift 3 | // format 4 | // 5 | // Created by 1 on 7/28/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_Stepper: View { 11 | @State private var StepperValue = 0 12 | 13 | var body: some View { 14 | VStack { 15 | Form { 16 | Stepper( 17 | value: $StepperValue, 18 | in: 1...100, 19 | step: 4 20 | ) { 21 | Text("Text: \(StepperValue)") 22 | } 23 | } 24 | } 25 | .navigationTitle("Stepper") 26 | .navigationBarTitleDisplayMode(.inline) 27 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "Stepper")) 28 | } 29 | } 30 | 31 | struct v_Stepper_Previews: PreviewProvider { 32 | static var previews: some View { 33 | v_Stepper() 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /hello/Components/v_Tab.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_Tab.swift 3 | // format 4 | // 5 | // Created by 1 on 7/28/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_Tab: View { 11 | var body: some View { 12 | VStack { 13 | TabView { 14 | Text("The First Tab") 15 | .badge(10) 16 | .tabItem { 17 | Image(systemName: "1.square.fill") 18 | Text("First") 19 | } 20 | Text("Another Tab") 21 | .tabItem { 22 | Image(systemName: "2.square.fill") 23 | Text("Second") 24 | } 25 | Text("The Last Tab") 26 | .tabItem { 27 | Image(systemName: "3.square.fill") 28 | Text("Third") 29 | } 30 | } 31 | } 32 | .navigationTitle("TabView") 33 | .navigationBarTitleDisplayMode(.inline) 34 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "TabView")) 35 | } 36 | } 37 | 38 | struct v_Tab_Previews: PreviewProvider { 39 | static var previews: some View { 40 | v_Tab() 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /hello/Components/v_Table.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewTable.swift 3 | // format 4 | // 5 | // Created by 1 on 7/28/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct Person: Identifiable { 11 | let givenName: String 12 | let familyName: String 13 | let emailAddress: String 14 | let id = UUID() 15 | } 16 | private var people = [ 17 | Person(givenName: "Juan", familyName: "Chavez", emailAddress: "juanchavez@icloud.com"), 18 | Person(givenName: "Mei", familyName: "Chen", emailAddress: "meichen@icloud.com"), 19 | Person(givenName: "Tom", familyName: "Clark", emailAddress: "tomclark@icloud.com"), 20 | Person(givenName: "Gita", familyName: "Kumar", emailAddress: "gitakumar@icloud.com") 21 | ] 22 | 23 | struct v_Table: View { 24 | 25 | var body: some View { 26 | VStack { 27 | 28 | Text("说明: table,仅适用于iOS 16.0+") 29 | .font(.caption) 30 | .foregroundColor(.gray) 31 | .frame(height: 80) 32 | 33 | if #available(iOS 16.0, *) { 34 | Table(people) { 35 | TableColumn("Given", value: \.givenName) 36 | TableColumn("Family", value: \.familyName) 37 | TableColumn("E-Mail", value: \.emailAddress) 38 | } 39 | } 40 | } 41 | .navigationTitle("Table") 42 | .navigationBarTitleDisplayMode(.inline) 43 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "Table")) 44 | } 45 | } 46 | 47 | struct v_Table_Previews: PreviewProvider { 48 | static var previews: some View { 49 | v_Table() 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /hello/Components/v_TextEditor.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_TextEditor.swift 3 | // format 4 | // 5 | // Created by 1 on 7/27/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_TextEditor: View { 11 | 12 | @State private var fullText: String = "A view that can display and edit long-form text." 13 | 14 | var body: some View { 15 | 16 | VStack { 17 | Form { 18 | Text("TextEditor").font(.title3) 19 | 20 | TextEditor(text: $fullText) 21 | .font(.custom("HelveticaNeue", size: 16)) 22 | .frame(minWidth: 0, maxWidth: .infinity, minHeight: 200, maxHeight: 300) 23 | } 24 | } 25 | .navigationTitle("TextEditor") 26 | .navigationBarTitleDisplayMode(.inline) 27 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "TextEditor")) 28 | } 29 | } 30 | 31 | struct v_TextEditor_Previews: PreviewProvider { 32 | static var previews: some View { 33 | v_TextEditor() 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /hello/Components/v_TextField.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_TextField.swift 3 | // format 4 | // 5 | // Created by 1 on 7/27/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_TextField: View { 11 | 12 | var body: some View { 13 | List { 14 | Section() { 15 | NavigationLink("输入框样式", destination: InputStyle()) 16 | } 17 | Section() { 18 | NavigationLink("自动获取焦点的输入框", destination: InputAutoFocus()) 19 | NavigationLink("收起键盘", destination: InputCloseKeyBoard()) 20 | } 21 | 22 | Section() { 23 | NavigationLink("带有图标的输入框", destination: InputWithIcon()) 24 | } 25 | 26 | Section() { 27 | NavigationLink("键盘右下角按钮", destination: InputKeyboardButtons()) 28 | } 29 | 30 | Section() { 31 | NavigationLink("输入框显示不同的键盘类型", destination: InputKeyboardType()) 32 | NavigationLink("密码输入框", destination: InputSecureField()) 33 | } 34 | 35 | Section() { 36 | NavigationLink("格式化输入内容 - formatter", destination: InputFormatter()) 37 | NavigationLink("onEditingChanged & onCommit", destination: InputOn()) 38 | } 39 | 40 | Section() { 41 | NavigationLink("输入框光标颜色", destination: InputAccentColor()) 42 | NavigationLink("输入框边框颜色", destination: InputBorder()) 43 | } 44 | } 45 | .navigationTitle("TextField") 46 | .navigationBarTitleDisplayMode(.inline) 47 | } 48 | } 49 | 50 | 51 | struct v_TextField_Previews: PreviewProvider { 52 | static var previews: some View { 53 | v_TextField() 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /hello/Components/v_TimelineView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_TimelineView.swift 3 | // format 4 | // 5 | // Created by 1 on 7/28/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | @available (iOS 15.0, *) 11 | struct v_TimelineView: View { 12 | var body: some View { 13 | VStack { 14 | Section() { 15 | Text("简介").font(.title) 16 | Text("TimelineView 是一种 SwiftUI 视图类型,可根据提供的时间表更新其正文。") 17 | .font(.caption) 18 | } 19 | .padding() 20 | 21 | Text("一个动画圆圈一分钟的快速示例") 22 | .font(.title3) 23 | .padding() 24 | 25 | TimelineView(.animation) { context in 26 | let value = secondsValue(for: context.date) 27 | 28 | Circle() 29 | .trim(from: 0, to: value) 30 | .stroke() 31 | } 32 | } 33 | .navigationTitle("TimelineView") 34 | .navigationBarTitleDisplayMode(.inline) 35 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "TimelineView")) 36 | } 37 | 38 | private func secondsValue(for date: Date) -> Double { 39 | let seconds = Calendar.current.component(.second, from: date) 40 | return Double(seconds) / 60 41 | } 42 | } 43 | 44 | struct v_TimelineView_Previews: PreviewProvider { 45 | static var previews: some View { 46 | v_TimelineView() 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /hello/Components/v_confirmationDialog.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_Dialog.swift 3 | // format 4 | // 5 | // Created by 1 on 7/30/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | @available (iOS 15.0, *) 11 | struct v_confirmationDialog: View { 12 | @State var isShowDialog: Bool = false 13 | 14 | var body: some View { 15 | VStack { 16 | Text("简介:confirmationDialog, 仅适用于 iOS 15.0+") 17 | .font(.caption) 18 | .foregroundColor(.gray) 19 | .frame(height: 80) 20 | 21 | Button("是否删除?") { 22 | self.isShowDialog = true 23 | } 24 | .confirmationDialog( "是否删除?", isPresented: $isShowDialog ) { 25 | Button("确认", role: .destructive) {} 26 | Button("取消", role: .cancel) {} 27 | } 28 | } 29 | .padding() 30 | .navigationTitle("confirmationDialog") 31 | .navigationBarTitleDisplayMode(.inline) 32 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "confirmationDialog")) 33 | } 34 | } 35 | 36 | struct v_confirmationDialog_Previews: PreviewProvider { 37 | static var previews: some View { 38 | v_confirmationDialog() 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /hello/Components/v_contextMenu.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_contextMenu.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/11/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_contextMenu: View { 11 | var body: some View { 12 | VStack { 13 | Text("contextMenu示例") 14 | .font(.title3) 15 | .padding() 16 | .contextMenu { 17 | Button("♥️ - Hearts", action: {}) 18 | Button("♣️ - Clubs", action: {}) 19 | Button("♠️ - Spades", action: {}) 20 | Button("♦️ - Diamonds", action: {}) 21 | } 22 | 23 | Text("长按即可看到效果") 24 | .font(.callout) 25 | .foregroundColor(.gray) 26 | } 27 | .navigationTitle("contextMenu") 28 | .navigationBarTitleDisplayMode(.inline) 29 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "contextMenu")) 30 | } 31 | } 32 | 33 | struct v_contextMenu_Previews: PreviewProvider { 34 | static var previews: some View { 35 | v_contextMenu() 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /hello/Components/v_extensionView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_extensionView.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/24/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | extension Button where Label == Image { 11 | init(iconName: String, action: @escaping () -> Void) { 12 | self.init(action: action) { 13 | Image(systemName: iconName) 14 | } 15 | } 16 | } 17 | 18 | extension View { 19 | func largeButton() -> some View { 20 | self 21 | .frame(maxWidth: .infinity) 22 | .frame(height: 50) 23 | .backgroundColor(.blue) 24 | .cornerRadius(10) 25 | .foregroundColor(.white) 26 | .padding() 27 | } 28 | } 29 | 30 | struct v_extensionView: View { 31 | 32 | @State var isShowToast: Bool = false 33 | @State var isShowSuccess: Bool = false 34 | 35 | var body: some View { 36 | VStack(alignment: .center) { 37 | Text("本页面的Button, 都用到了extension协议,具体请点击右上角查看源码。") 38 | .foregroundColor(.gray) 39 | .font(.callout) 40 | .frame(height: 120) 41 | .padding() 42 | 43 | // 示例1 44 | Button(iconName: "paperplane", action: { }) 45 | 46 | // 示例2 47 | Button("提交", action: { }) 48 | .largeButton() 49 | 50 | Spacer() 51 | } 52 | .navigationTitle("extension View") 53 | .navigationBarTitleDisplayMode(.inline) 54 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "extensionView")) 55 | } 56 | } 57 | 58 | 59 | struct v_extensionView_Previews: PreviewProvider { 60 | static var previews: some View { 61 | v_extensionView() 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /hello/Components/v_fullScreenCover.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewfullScreenCover.swift 3 | // format 4 | // 5 | // Created by 1 on 7/28/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | @available (iOS 14.0, *) 11 | struct v_fullScreenCover: View { 12 | @State private var isPresenting = false 13 | 14 | var body: some View { 15 | VStack { 16 | Button(action: { 17 | isPresenting = true 18 | }, label: { 19 | Text("显示 Full Screen Cover").font(.title) 20 | }) 21 | .fullScreenCover(isPresented: $isPresenting, onDismiss: didDismiss) { 22 | VStack { 23 | Text("2022年").font(.title) 24 | } 25 | .onTapGesture { 26 | isPresenting = false 27 | } 28 | .frame(maxWidth: .infinity, maxHeight: .infinity) 29 | .background(.gray.opacity(0.2)) 30 | .ignoresSafeArea(edges: .all) 31 | 32 | } 33 | 34 | Text("Presents a modal view that covers as much of the screen as possible using the binding you provide as a data source for the sheet’s content.") 35 | .font(.body) 36 | .padding() 37 | } 38 | .navigationTitle(".fullScreenCover") 39 | .navigationBarTitleDisplayMode(.inline) 40 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "fullScreenCover")) 41 | } 42 | 43 | func didDismiss() { 44 | 45 | } 46 | } 47 | 48 | struct v_fullScreenCover_Previews: PreviewProvider { 49 | static var previews: some View { 50 | v_fullScreenCover() 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /hello/Components/v_ignoresSafeArea.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_ignoresSafeArea.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/21/22. 6 | // 关于安全区域 7 | 8 | import SwiftUI 9 | 10 | struct v_ignoresSafeArea: View { 11 | @State var isSwitch: Bool = false 12 | 13 | var body: some View { 14 | ZStack { 15 | Toggle(isOn: $isSwitch, label: { 16 | Text("是否使用 .ignoresSafeArea()") 17 | }) 18 | .zIndex(100) 19 | .padding() 20 | 21 | if isSwitch { 22 | LinearGradient(gradient: Gradient(colors: [Color(#colorLiteral(red: 0.2392156869, green: 0.6745098233, blue: 0.9686274529, alpha: 1)), Color(#colorLiteral(red: 0.4745098054, green: 0.8392156959, blue: 0.9764705896, alpha: 1))]), startPoint: .topLeading, endPoint: .bottomTrailing) 23 | .ignoresSafeArea() 24 | } else { 25 | LinearGradient(gradient: Gradient(colors: [Color(#colorLiteral(red: 0.2392156869, green: 0.6745098233, blue: 0.9686274529, alpha: 1)), Color(#colorLiteral(red: 0.4745098054, green: 0.8392156959, blue: 0.9764705896, alpha: 1))]), startPoint: .topLeading, endPoint: .bottomTrailing) 26 | } 27 | } 28 | .navigationTitle(".ignoresSafeArea()") 29 | .navigationBarTitleDisplayMode(.inline) 30 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "ignoresSafeArea")) 31 | } 32 | } 33 | 34 | struct v_ignoresSafeArea_Previews: PreviewProvider { 35 | static var previews: some View { 36 | v_ignoresSafeArea() 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /hello/Components/v_navigationBarItems.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_navigationBarItems.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/20/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | @available (iOS, introduced: 13.0, deprecated: 16.0, message: "此方法仅仅适用于13.0~16.0, iOS 16.0之后,推荐使用 .toolbar()") 11 | struct v_navigationBarItems: View { 12 | 13 | // dismiss方法 适用于 iOS 15.0+ 14 | @Environment(\.dismiss) private var dismiss 15 | 16 | var body: some View { 17 | VStack(alignment: .leading) { 18 | Text("请注意,顶部导航栏左边和右边按钮。\n本示例用到了 .navigationBarItems() 方法。\n此方法适用于iOS 13.0-16.0, iOS 16.0之后,推荐使用 .toolbar() ") 19 | .font(.callout) 20 | .foregroundColor(.gray) 21 | .padding() 22 | .modifier(buttonViewCodeAndDocs(pageType: "SwiftUI",pageID: "navigationBarItems")) 23 | Spacer() 24 | } 25 | .navigationBarBackButtonHidden(true) 26 | .navigationBarItems( 27 | leading: Button(action: { 28 | self.dismiss() 29 | }) { 30 | Text("< 返回") 31 | }, 32 | trailing: Button(action: { 33 | 34 | }) { 35 | Text("分享") 36 | } 37 | ) 38 | } 39 | } 40 | 41 | struct v_navigationBarItems_Previews: PreviewProvider { 42 | static var previews: some View { 43 | v_navigationBarItems() 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /hello/Components/v_offset.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_offset.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/23/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_offset: View { 11 | var body: some View { 12 | VStack { 13 | Text("如下示例,中间圆,设置了x和y的偏移量为25。但是视图的原始尺寸没有因为设置offset发生更改,仅会影响子视图,换而言之,offset不会影响布局。") 14 | .font(.callout) 15 | .foregroundColor(.gray) 16 | .padding(20) 17 | 18 | HStack { 19 | Circle().fill(Color.red) 20 | Circle().fill(Color.green).offset(x: 25.0, y: 25.0) 21 | Circle().fill(Color.yellow) 22 | } 23 | .frame(width: 210, height: 66) 24 | .border(Color.black) 25 | } 26 | .navigationTitle(".offset()") 27 | .navigationBarTitleDisplayMode(.inline) 28 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "offset")) 29 | } 30 | } 31 | 32 | struct v_offset_Previews: PreviewProvider { 33 | static var previews: some View { 34 | v_offset() 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /hello/Components/v_position.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_position.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/22/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_position: View { 11 | var body: some View { 12 | VStack { 13 | Text("如下所示,红色图标,是使用.position(x: 100, y: 100)的效果。") 14 | .foregroundColor(.gray) 15 | .font(.callout) 16 | .padding() 17 | 18 | Image(systemName: "figure.climbing") 19 | .foregroundColor(.red) 20 | .font(.largeTitle) 21 | .position(x: 100, y: 100) 22 | } 23 | .navigationTitle("position") 24 | .navigationBarTitleDisplayMode(.inline) 25 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "position")) 26 | } 27 | } 28 | 29 | struct v_position_Previews: PreviewProvider { 30 | static var previews: some View { 31 | v_position() 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /hello/Components/v_safeAreaInset.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_safeAreaInset.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/22/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_safeAreaInset: View { 11 | @State var setStatus: Bool = false 12 | 13 | var body: some View { 14 | ScrollView { 15 | ForEach(1..<100) { item in 16 | Text("number: \(item)") 17 | .padding(.vertical) 18 | } 19 | .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .leading) 20 | .padding() 21 | } 22 | .safeAreaInset(edge: .bottom, content: { 23 | Color.clear.frame(height: setStatus ? 150 : 0) 24 | }) 25 | .overlay( 26 | showList, alignment: .bottom 27 | ) 28 | .navigationTitle(".safeAreaInset()") 29 | .navigationBarTitleDisplayMode(.inline) 30 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI", pageID: "safeAreaInset")) 31 | } 32 | 33 | var showList: some View { 34 | VStack() { 35 | Text("滑动页面内容到底部时,会有部分内容被遮挡。使用 .safeAreaInset() 可以解决此问题。") 36 | Button(action: { 37 | self.setStatus.toggle() 38 | }, label: { 39 | Text(setStatus ? "清除safeAreaInset" : "设置safeAreaInset") 40 | .foregroundColor(.white) 41 | }) 42 | .buttonStyle(.borderedProminent) 43 | } 44 | .padding() 45 | .frame(height: 150) 46 | .frame(maxWidth: .infinity) 47 | .foregroundColor(.white) 48 | .backgroundColor(.cyan) 49 | } 50 | } 51 | 52 | struct v_safeAreaInset_Previews: PreviewProvider { 53 | static var previews: some View { 54 | v_safeAreaInset() 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /hello/Components/v_section.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_section.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/22/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_section: View { 11 | @State var phone: String = "" 12 | @State var passwd: String = "" 13 | 14 | var body: some View { 15 | Form { 16 | Text("关于Section, 常用来分组。通常在 List、Picker、Form中使用。\n\n如下示例,注意文字: 水果分类、语言分类") 17 | .foregroundColor(.gray) 18 | .font(.callout) 19 | .frame(minHeight: 60) 20 | 21 | Section("水果分类") { 22 | Text("香蕉") 23 | Text("苹果") 24 | } 25 | 26 | Section(header: Text("语言分类").foregroundColor(.red)) { 27 | Text("Python") 28 | Text("JavaScript") 29 | } 30 | 31 | Section("") { 32 | TextField("手机号", text: $phone) 33 | TextField("密码", text: $passwd) 34 | } 35 | } 36 | .navigationTitle("Section") 37 | .navigationBarTitleDisplayMode(.inline) 38 | .modifier(navBarViewCodeAndDocs(pageType: "SwiftUI",pageID: "Section")) 39 | } 40 | } 41 | 42 | struct v_section_Previews: PreviewProvider { 43 | static var previews: some View { 44 | v_section() 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /hello/Components/v_shape.swift: -------------------------------------------------------------------------------- 1 | // 2 | // v_shape.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 7/31/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct v_shape: View { 11 | var body: some View { 12 | List { 13 | Section() { 14 | NavigationLink("Circle() - 圆形|环形", destination: v_Circle()) 15 | NavigationLink("Circle() - 圆形进度条", destination: v_CircleProgressBar()) 16 | } 17 | 18 | Section() { 19 | NavigationLink("Rectangle()", destination: v_Rectangle()) 20 | NavigationLink("RoundedRectangle()", destination: v_RoundedRectangle()) 21 | } 22 | 23 | Section() { 24 | NavigationLink("Ellipse()", destination: v_Ellipse()) 25 | } 26 | 27 | Section() { 28 | NavigationLink("Capsule() - 胶囊", destination: v_Capsule()) 29 | NavigationLink("Capsule() 组合", destination: v_CapsuleGroup()) 30 | } 31 | 32 | Section() { 33 | NavigationLink("Path()", destination: v_Path()) 34 | } 35 | } 36 | .navigationTitle("Shapes") 37 | } 38 | } 39 | 40 | struct v_shape_Previews: PreviewProvider { 41 | static var previews: some View { 42 | v_shape() 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /hello/Config/ConfigSwiftUI_Desc.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ConfigSwiftUI_Desc.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/10/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | // sheet 11 | let ui_sheet_available_versions: [String] = ["iOS 13.0+"] 12 | let ui_sheet_desc:String = ".sheet() 方法,用于在页面底部显示工作表。iOS 16.0+,增加 .presentationDetents() 修饰符,可以控制sheet大小。语法如下: " 13 | let ui_sheet_declaration:String = """ 14 | func sheet( 15 | isPresented: Binding, 16 | onDismiss: (() -> Void)? = nil, 17 | content: @escaping () -> Content 18 | ) -> some View where Content : View 19 | """ 20 | 21 | // Form 22 | let ui_form_available_versions: [String] = ["iOS 13.0+", "macOS 10.15+"] 23 | let ui_form_desc: String = "Form, 将适合表单的样式视图组合到一起,如按钮、列表、Pikcer、Toggle等" 24 | let ui_form_declaration:String = """ 25 | struct Form where Content : View 26 | """ 27 | -------------------------------------------------------------------------------- /hello/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /hello/ReleaseNote.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ReleaseNote.swift 3 | // Hello 4 | // 5 | // Created by 1 on 10/7/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | fileprivate var changeLogs: String = """ 11 | v1.0.3 12 | * App上线了 13 | """ 14 | 15 | struct ReleaseNote: View { 16 | var body: some View { 17 | ScrollView { 18 | Text(changeLogs) 19 | .lineSpacing(10) 20 | .padding() 21 | } 22 | } 23 | } 24 | 25 | struct ReleaseNote_Previews: PreviewProvider { 26 | static var previews: some View { 27 | ReleaseNote() 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /hello/Resouces.bundle/App/firstSight/CreateProject.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | CreateProject 8 | 9 |
10 |

第1步:如下图所示,点击: Create a new Xcode Project

第2步:点击 Create a new Xcode Project 后,出现如下界面,选择 App 或其它Application类型,然后点击底部按钮 Next

第3步:如下图,填写: Product Name、Team、Organization Identifier。Interface和Language等其它项默认即可。填写后,点击底部按钮 Next

项目创建后,Xcode显示界面如下:

此时,将iPhone设备,连接到电脑上,然后按下快捷键Command+R,即可在手机预览。

11 | 12 | 13 | -------------------------------------------------------------------------------- /hello/Resouces.bundle/App/firstSight/XcodeInstall.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | XcodeInstall 8 | 9 |
10 |

Xcode 是运行在操作系统MacOS X上的集成开发工具。Xcode是开发 macOS 和 iOS 应用程序的最快捷的方式。

目前2022年9月,Xcode最新版本是 14.0

在 Mac 电脑上,打开 App Store.app,搜索Xcode,点击 获取 按钮。

如下图所示:

Xcode软件体积很大,安装速度取决于您的网络。

安装完成后,在电脑上找到Xcode,点击启动。

11 | 12 | 13 | -------------------------------------------------------------------------------- /hello/Resouces.bundle/App/firstSight/introduce.md: -------------------------------------------------------------------------------- 1 | 2 | 2022年8月初的时候,想做一款iOS 记账类的App。在此之前,未接触过iOS开发。 3 | 4 | 通过网络搜索,了解到Swift和SwiftUI。在短暂的调研后,投入时间开始学习,每天学习2~3小时,结果是惊喜的。 5 | 6 | 学习SwiftUI之时,随着时间推移,积累的代码,发现可以直接转换为一个Swift学习App。 7 | 8 | 所以,便有了它。 9 | -------------------------------------------------------------------------------- /hello/Resouces.bundle/App/firstSight/static/create_project_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Resouces.bundle/App/firstSight/static/create_project_1.jpg -------------------------------------------------------------------------------- /hello/Resouces.bundle/App/firstSight/static/create_project_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Resouces.bundle/App/firstSight/static/create_project_2.jpg -------------------------------------------------------------------------------- /hello/Resouces.bundle/App/firstSight/static/create_project_3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Resouces.bundle/App/firstSight/static/create_project_3.jpg -------------------------------------------------------------------------------- /hello/Resouces.bundle/App/firstSight/static/create_project_4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Resouces.bundle/App/firstSight/static/create_project_4.jpg -------------------------------------------------------------------------------- /hello/Resouces.bundle/App/firstSight/static/xcode_details.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Resouces.bundle/App/firstSight/static/xcode_details.jpg -------------------------------------------------------------------------------- /hello/Resouces.bundle/App/firstSight/static/xcode_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Resouces.bundle/App/firstSight/static/xcode_icon.png -------------------------------------------------------------------------------- /hello/Resouces.bundle/Root.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | StringsTable 6 | Root 7 | PreferenceSpecifiers 8 | 9 | 10 | Type 11 | PSGroupSpecifier 12 | Title 13 | Group 14 | 15 | 16 | Type 17 | PSTextFieldSpecifier 18 | Title 19 | Name 20 | Key 21 | name_preference 22 | DefaultValue 23 | 24 | IsSecure 25 | 26 | KeyboardType 27 | Alphabet 28 | AutocapitalizationType 29 | None 30 | AutocorrectionType 31 | No 32 | 33 | 34 | Type 35 | PSToggleSwitchSpecifier 36 | Title 37 | Enabled 38 | Key 39 | enabled_preference 40 | DefaultValue 41 | 42 | 43 | 44 | Type 45 | PSSliderSpecifier 46 | Key 47 | slider_preference 48 | DefaultValue 49 | 0.5 50 | MinimumValue 51 | 0 52 | MaximumValue 53 | 1 54 | MinimumValueImage 55 | 56 | MaximumValueImage 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /hello/Resouces.bundle/en.lproj/Root.strings: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Resouces.bundle/en.lproj/Root.strings -------------------------------------------------------------------------------- /hello/Resouces.bundle/media/example_audio.m4a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wan-dl/swift-swiftui-example/65e9fc78e37488bd7b545486bc06ebcf1090416b/hello/Resouces.bundle/media/example_audio.m4a -------------------------------------------------------------------------------- /hello/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 8/12/22. 6 | // 7 | 8 | import Foundation 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | override func viewDidLoad() { 14 | super.viewDidLoad() 15 | view.backgroundColor = .red 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /hello/Views/NavigationBar.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NavigationBar.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 7/31/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct NavigationBar: View { 11 | var title: String = "Title" 12 | 13 | @State var isGoSearch: Bool = false 14 | 15 | var body: some View { 16 | ZStack { 17 | Color.clear 18 | .background(.ultraThinMaterial) 19 | .blur(radius: 10) 20 | 21 | NavigationLink { 22 | About() 23 | } label: { 24 | // Text(title) 25 | // .font(.largeTitle) 26 | // .foregroundColor(.primary) 27 | // .padding(.leading, 20) 28 | Image(systemName: "slider.horizontal.3") 29 | .font(.title) 30 | .padding(.leading, 20) 31 | } 32 | .frame(maxWidth: .infinity, alignment: .leading) 33 | 34 | NavigationLink { 35 | GlobalSearch() 36 | } label: { 37 | Image(systemName: "magnifyingglass") 38 | .foregroundColor(.black) 39 | } 40 | .frame(maxWidth: .infinity, alignment: .trailing) 41 | .offset(x: -20) 42 | } 43 | .frame(height: 77) 44 | .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading) 45 | } 46 | } 47 | 48 | struct NavigationBar_Previews: PreviewProvider { 49 | static var previews: some View { 50 | NavigationBar(title: "Home") 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /hello/example/p_ScrollWithRotate3DEffect.swift: -------------------------------------------------------------------------------- 1 | // 2 | // p_ScrollWithRotate3DEffect.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 8/2/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct p_ScrollWithRotate3DEffect: View { 11 | var body: some View { 12 | VStack { 13 | Text("Horizontal Scroll with rotate3DEffect") 14 | .font(.title) 15 | .offset(y: -100) 16 | 17 | ScrollView(.horizontal, showsIndicators: false) { 18 | HStack(spacing: 16) { 19 | ForEach(0 ..< 5) { item in 20 | GeometryReader { geometry in 21 | RoundedRectangle(cornerRadius: 30) 22 | .fill( 23 | .blue 24 | ) 25 | .rotation3DEffect( 26 | Angle( 27 | degrees: Double((geometry.frame(in: .global).minX - 20) / -20) 28 | ), 29 | axis: (x: 0, y: 1, z: 0), 30 | anchor: .center, 31 | anchorZ: 0.0, 32 | perspective: 1.0 33 | ) 34 | } 35 | .frame(width: 300, height: 300) 36 | } 37 | } 38 | .padding() 39 | } 40 | } 41 | } 42 | } 43 | 44 | struct p_ScrollWithRotate3DEffect_Previews: PreviewProvider { 45 | static var previews: some View { 46 | p_ScrollWithRotate3DEffect() 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /hello/example/p_contentShape.swift: -------------------------------------------------------------------------------- 1 | // 2 | // p_contentShape.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 9/4/22. 6 | // 控制台视图点击区域 7 | 8 | import SwiftUI 9 | 10 | struct p_contentShape: View { 11 | var body: some View { 12 | VStack { 13 | 14 | VStack { 15 | Image(systemName: "person.circle").resizable().frame(width: 50, height: 50) 16 | Spacer().frame(height: 50) 17 | Text("Paul Hudson") 18 | } 19 | .contentShape(Rectangle()) 20 | .onTapGesture { 21 | print("Show details for user") 22 | } 23 | 24 | Text("简介:本页面示例,使用了.contentShape()方法。") 25 | .font(.caption) 26 | .foregroundColor(.gray) 27 | .frame(height: 80) 28 | .offset(y: 50) 29 | } 30 | .padding() 31 | .navigationTitle("contentShape") 32 | .navigationBarTitleDisplayMode(.inline) 33 | } 34 | } 35 | 36 | struct p_contentShape_Previews: PreviewProvider { 37 | static var previews: some View { 38 | p_contentShape() 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /hello/example/p_environment.swift: -------------------------------------------------------------------------------- 1 | // 2 | // p_environment.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 8/2/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | @available (iOS 14.0, *) 11 | struct p_environment: View { 12 | @EnvironmentObject var envMedicine: Medicine 13 | 14 | var body: some View { 15 | VStack(alignment: .leading, spacing: 20) { 16 | Text("\(envMedicine.name)") 17 | 18 | Text("备注:如上信息,是从其它视图传递过来的数据。\n涉及到代码:@EnvironmentObject") 19 | .font(.footnote) 20 | } 21 | .navigationTitle("接收其它视图传递的数据") 22 | .navigationBarTitleDisplayMode(.inline) 23 | } 24 | } 25 | 26 | struct p_environment_Previews: PreviewProvider { 27 | static var previews: some View { 28 | p_environment() 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /hello/example/p_markdownWithAttributedString.swift: -------------------------------------------------------------------------------- 1 | // 2 | // p_markdownWithAttributedString.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 8/3/22. 6 | // 7 | 8 | import SwiftUI 9 | //import lnk 10 | struct p_markdownWithAttributedString: View { 11 | @State var mdData: AttributedString = "" 12 | let markdown = """ 13 | ```javascript 14 | let abc = "xxx" 15 | ``` 16 | 访问 [Baidu](https://www.baidu.com) 搜索 17 | """ 18 | 19 | var body: some View { 20 | VStack() { 21 | Text(mdData) 22 | .onAppear() { 23 | do { 24 | mdData = try AttributedString(markdown: markdown) 25 | } catch { 26 | print("Error creating AttributedString: \(error)") 27 | } 28 | } 29 | .padding() 30 | .frame(height: 300) 31 | .background(.gray.opacity(0.2)) 32 | .foregroundColor(.black) 33 | .font(.body) 34 | } 35 | .navigationTitle("MarkDown渲染") 36 | } 37 | } 38 | 39 | struct p_markdownWithAttributedString_Previews: PreviewProvider { 40 | static var previews: some View { 41 | p_markdownWithAttributedString() 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /hello/example/p_tabview.swift: -------------------------------------------------------------------------------- 1 | // 2 | // p_tabview.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 7/31/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct ColorName: Identifiable { 11 | let id = UUID() 12 | let name: Color 13 | } 14 | 15 | let ColorList: [ColorName] = [ 16 | ColorName(name: .green.opacity(0.4)), 17 | ColorName(name: .yellow.opacity(0.4)), 18 | ColorName(name: .blue.opacity(0.4)) 19 | ] 20 | 21 | struct p_tabview: View { 22 | 23 | var body: some View { 24 | VStack { 25 | TabView { 26 | ForEach(ColorList) {item in 27 | Rectangle() 28 | .fill(item.name) 29 | .cornerRadius(20) 30 | .frame(maxWidth: .infinity) 31 | } 32 | } 33 | .tabViewStyle(.page) 34 | .padding() 35 | .frame(height: 300) 36 | .cornerRadius(20) 37 | 38 | Text("备注:轮播图示例,主要用了TabView") 39 | } 40 | .navigationTitle("轮播图示例") 41 | .navigationBarTitleDisplayMode(.inline) 42 | } 43 | } 44 | 45 | struct p_tabview_Previews: PreviewProvider { 46 | static var previews: some View { 47 | p_tabview() 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /hello/example/p_tmp.swift: -------------------------------------------------------------------------------- 1 | // 2 | // tmp.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 8/2/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct p_tmp: View { 11 | @State var show: Bool = false 12 | 13 | var body: some View { 14 | VStack { 15 | 16 | } 17 | } 18 | } 19 | 20 | struct p_tmp_Previews: PreviewProvider { 21 | static var previews: some View { 22 | p_tmp() 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /hello/example/p_toolbar.swift: -------------------------------------------------------------------------------- 1 | // 2 | // p_toolbar.swift 3 | // HelloSwift 4 | // 5 | // Created by 1 on 8/2/22. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct p_toolbar: View { 11 | @State var text: String = "" 12 | @State var fontType: Font = .body 13 | 14 | var body: some View { 15 | VStack { 16 | TextEditor(text: $text) 17 | .frame(height: 150) 18 | .font(fontType) 19 | .padding() 20 | .overlay( 21 | RoundedRectangle(cornerRadius: 8) 22 | .stroke(Color.primary, lineWidth: 1) 23 | ) 24 | .padding() 25 | .toolbar { 26 | ToolbarItemGroup(placement: .keyboard) { 27 | Button("加粗") { fontType = .body.bold() } 28 | Button("斜体") { fontType = .body.italic() } 29 | Spacer() 30 | } 31 | } 32 | 33 | Text("备注:请将光标置于输入框中,然后查看键盘") 34 | } 35 | .navigationTitle("toolbar示例") 36 | .navigationBarTitleDisplayMode(.inline) 37 | } 38 | } 39 | 40 | struct p_toolbar_Previews: PreviewProvider { 41 | static var previews: some View { 42 | p_toolbar() 43 | } 44 | } 45 | --------------------------------------------------------------------------------