├── LICENSE ├── README.md ├── SwiftUI-example ├── SwiftUI-example.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ └── zhudekun.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── zhudekun.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints_v2.xcbkptlist │ │ └── xcschemes │ │ └── xcschememanagement.plist └── SwiftUI-example │ ├── AppDelegate.swift │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ └── img.imageset │ │ ├── 589c299564dbf.jpg │ │ └── Contents.json │ ├── Base.lproj │ └── LaunchScreen.storyboard │ ├── ContentView.swift │ ├── Info.plist │ ├── Preview Content │ └── Preview Assets.xcassets │ │ └── Contents.json │ ├── SceneDelegate.swift │ └── SwiftUI.swift ├── p1.png ├── p2.png ├── p3.png ├── p5.png ├── p6.png └── p7.png /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 DKJone 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SwiftUI examples 2 | 3 | 苹果与2019年6月4日发布的全新UI框架旨在统一苹果各平台的UI(包括UIKit ,AppKit...),这是一些例子(包含部分来自官方的教程)。 4 | 在开始之前,你需要如下准备 5 | 6 | | 工具  | 是否必须 | 7 | | --- | --- | 8 | | [Xcode 11 beta](https://developer.apple.com/download/)  | ✅ | 9 | | mac OS Mojave or Higher | ❎ | 10 | 11 | (如果想要体验实时预览和完整的Xcode 11 功能,需要macOS 10.15 beta) 12 | 13 | 14 | 开始第一个demo 15 | 1.创建新的项目,并勾选使用SwiftUI 16 | 17 | | ![](./p1.png) | ![](./p2.png) | ![](./p3.png) | 18 | | --- | --- | --- | 19 | 20 | 2.打开`ContentView.swift`文件,文件内容如下 21 | ```swift 22 | import SwiftUI 23 | 24 | struct ContentView: View { 25 | var body: some View { 26 | Text("Hello SwiftUI") 27 | } 28 | } 29 | #if DEBUG 30 | struct ContentView_Previews: PreviewProvider { 31 | static var previews: some View { 32 | ContentView() 33 | } 34 | } 35 | #endif 36 | ``` 37 | 如果使用的是macOS 10.15 beta 版本的系统则可以打开实时预览页面 38 | ![](./p5.png) 39 | (如果是macOS 10.14打开也只有源代码编辑界面) 40 | 修改UI只需要按住command点击对应了的UI控件(或代码)编辑即可如下图:(macos 10.14不会弹出此菜单),修改预览中路那个的属性会直接自动同步更新源代码,更改代码会更新预览视图 41 | 42 | | ![](./p6.png) | ![](./p7.png) | 43 | | --- | --- | 44 | 45 | 3.修改代码实现自定义视图(点击源码中Text跳转到定义,查看SwiftUI定义的所有控件代码约1W行 )示例代码 46 | ```swift 47 | // 48 | // ContentView.swift 49 | // SwiftUI-example 50 | import SwiftUI 51 | struct ContentView: View { 52 | var body: some View { 53 | // 创建 文本(Label) 54 | let aText = Text("Hello SwiftUI") 55 | .color(.yellow) 56 | .strikethrough() 57 | .font(.system(size: 14.1)) 58 | 59 | // 创建 按钮(Button) 60 | let aButton = Button(action: { 61 | print(#function) 62 | }) { 63 | Text("Hello SwiftUI") 64 | } 65 | 66 | let aView = AnyView(aText) 67 | 68 | // 创建图片 69 | let anImage = Image("img") 70 | .aspectRatio(contentMode: .fit) 71 | 72 | // 布局各视图 73 | return VStack { 74 | anImage 75 | aText 76 | aButton 77 | aView 78 | } 79 | } 80 | } 81 | #if DEBUG 82 | struct ContentView_Previews: PreviewProvider { 83 | static var previews: some View { 84 | ContentView() 85 | } 86 | } 87 | #endif 88 | ``` 89 | 90 | 91 | 92 | 更多官方示例源码: 93 | 1. [创建和组合视图(Creating and Combining Views)](https://developer.apple.com/tutorials/swiftui/creating-and-combining-views) 94 | 2. [列表和导航栏(Building Lists and Navigation)](https://developer.apple.com/tutorials/swiftui/building-lists-and-navigation) 95 | 3. [处理用户事件(Handling User Input)](https://developer.apple.com/tutorials/swiftui/handling-user-input) 96 | 97 | 4. [绘图路径和形状(Drawing Paths and Shapes)](https://developer.apple.com/tutorials/swiftui/drawing-paths-and-shapes) 98 | 5. [动画和转场(Animating Views and Transitions)](https://developer.apple.com/tutorials/swiftui/animating-views-and-transitions) 99 | 6. [复杂界面组合(Composing Complex Interfaces)](https://developer.apple.com/tutorials/swiftui/composing-complex-interfaces) 100 | 7. UIKit混合开发[(Interfacing with UIKit)](https://developer.apple.com/tutorials/swiftui/interfacing-with-uikit)&[(Working with UI Controls)](https://developer.apple.com/tutorials/swiftui/working-with-ui-controls) 101 | 102 | 如果你想了解更多关于SwiftUI的内容,你可以通过以下途径获取 103 | 104 | 1. [SwiftUI Apple 官方教程](https://developer.apple.com/tutorials/swiftui/creating-and-combining-views) 105 | 2. [SwiftUI Apple Documentation](https://developer.apple.com/documentation/swiftui) 106 | 3. [WWDC19 SwiftUI](https://developer.apple.com/videos/play/wwdc2019/238/) 107 | 4. [Xcode SwiftUI Source](./SwiftUI-example/SwiftUI-example/SwiftUI.swift) -------------------------------------------------------------------------------- /SwiftUI-example/SwiftUI-example.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 119C5BDB22A635AA003EF04A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 119C5BDA22A635AA003EF04A /* AppDelegate.swift */; }; 11 | 119C5BDD22A635AA003EF04A /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 119C5BDC22A635AA003EF04A /* SceneDelegate.swift */; }; 12 | 119C5BDF22A635AA003EF04A /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 119C5BDE22A635AA003EF04A /* ContentView.swift */; }; 13 | 119C5BE122A635AB003EF04A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 119C5BE022A635AB003EF04A /* Assets.xcassets */; }; 14 | 119C5BE422A635AB003EF04A /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 119C5BE322A635AB003EF04A /* Preview Assets.xcassets */; }; 15 | 119C5BE722A635AB003EF04A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 119C5BE522A635AB003EF04A /* LaunchScreen.storyboard */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | 119C5BD722A635AA003EF04A /* SwiftUI-example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "SwiftUI-example.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 20 | 119C5BDA22A635AA003EF04A /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 21 | 119C5BDC22A635AA003EF04A /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 22 | 119C5BDE22A635AA003EF04A /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 23 | 119C5BE022A635AB003EF04A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 24 | 119C5BE322A635AB003EF04A /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 25 | 119C5BE622A635AB003EF04A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 26 | 119C5BE822A635AB003EF04A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 27 | /* End PBXFileReference section */ 28 | 29 | /* Begin PBXFrameworksBuildPhase section */ 30 | 119C5BD422A635AA003EF04A /* Frameworks */ = { 31 | isa = PBXFrameworksBuildPhase; 32 | buildActionMask = 2147483647; 33 | files = ( 34 | ); 35 | runOnlyForDeploymentPostprocessing = 0; 36 | }; 37 | /* End PBXFrameworksBuildPhase section */ 38 | 39 | /* Begin PBXGroup section */ 40 | 119C5BCE22A635AA003EF04A = { 41 | isa = PBXGroup; 42 | children = ( 43 | 119C5BD922A635AA003EF04A /* SwiftUI-example */, 44 | 119C5BD822A635AA003EF04A /* Products */, 45 | ); 46 | sourceTree = ""; 47 | }; 48 | 119C5BD822A635AA003EF04A /* Products */ = { 49 | isa = PBXGroup; 50 | children = ( 51 | 119C5BD722A635AA003EF04A /* SwiftUI-example.app */, 52 | ); 53 | name = Products; 54 | sourceTree = ""; 55 | }; 56 | 119C5BD922A635AA003EF04A /* SwiftUI-example */ = { 57 | isa = PBXGroup; 58 | children = ( 59 | 119C5BDA22A635AA003EF04A /* AppDelegate.swift */, 60 | 119C5BDC22A635AA003EF04A /* SceneDelegate.swift */, 61 | 119C5BDE22A635AA003EF04A /* ContentView.swift */, 62 | 119C5BE022A635AB003EF04A /* Assets.xcassets */, 63 | 119C5BE522A635AB003EF04A /* LaunchScreen.storyboard */, 64 | 119C5BE822A635AB003EF04A /* Info.plist */, 65 | 119C5BE222A635AB003EF04A /* Preview Content */, 66 | ); 67 | path = "SwiftUI-example"; 68 | sourceTree = ""; 69 | }; 70 | 119C5BE222A635AB003EF04A /* Preview Content */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | 119C5BE322A635AB003EF04A /* Preview Assets.xcassets */, 74 | ); 75 | path = "Preview Content"; 76 | sourceTree = ""; 77 | }; 78 | /* End PBXGroup section */ 79 | 80 | /* Begin PBXNativeTarget section */ 81 | 119C5BD622A635AA003EF04A /* SwiftUI-example */ = { 82 | isa = PBXNativeTarget; 83 | buildConfigurationList = 119C5BEB22A635AB003EF04A /* Build configuration list for PBXNativeTarget "SwiftUI-example" */; 84 | buildPhases = ( 85 | 119C5BD322A635AA003EF04A /* Sources */, 86 | 119C5BD422A635AA003EF04A /* Frameworks */, 87 | 119C5BD522A635AA003EF04A /* Resources */, 88 | ); 89 | buildRules = ( 90 | ); 91 | dependencies = ( 92 | ); 93 | name = "SwiftUI-example"; 94 | productName = "SwiftUI-example"; 95 | productReference = 119C5BD722A635AA003EF04A /* SwiftUI-example.app */; 96 | productType = "com.apple.product-type.application"; 97 | }; 98 | /* End PBXNativeTarget section */ 99 | 100 | /* Begin PBXProject section */ 101 | 119C5BCF22A635AA003EF04A /* Project object */ = { 102 | isa = PBXProject; 103 | attributes = { 104 | LastSwiftUpdateCheck = 1100; 105 | LastUpgradeCheck = 1100; 106 | ORGANIZATIONNAME = DKJone; 107 | TargetAttributes = { 108 | 119C5BD622A635AA003EF04A = { 109 | CreatedOnToolsVersion = 11.0; 110 | }; 111 | }; 112 | }; 113 | buildConfigurationList = 119C5BD222A635AA003EF04A /* Build configuration list for PBXProject "SwiftUI-example" */; 114 | compatibilityVersion = "Xcode 9.3"; 115 | developmentRegion = en; 116 | hasScannedForEncodings = 0; 117 | knownRegions = ( 118 | en, 119 | Base, 120 | ); 121 | mainGroup = 119C5BCE22A635AA003EF04A; 122 | productRefGroup = 119C5BD822A635AA003EF04A /* Products */; 123 | projectDirPath = ""; 124 | projectRoot = ""; 125 | targets = ( 126 | 119C5BD622A635AA003EF04A /* SwiftUI-example */, 127 | ); 128 | }; 129 | /* End PBXProject section */ 130 | 131 | /* Begin PBXResourcesBuildPhase section */ 132 | 119C5BD522A635AA003EF04A /* Resources */ = { 133 | isa = PBXResourcesBuildPhase; 134 | buildActionMask = 2147483647; 135 | files = ( 136 | 119C5BE722A635AB003EF04A /* LaunchScreen.storyboard in Resources */, 137 | 119C5BE422A635AB003EF04A /* Preview Assets.xcassets in Resources */, 138 | 119C5BE122A635AB003EF04A /* Assets.xcassets in Resources */, 139 | ); 140 | runOnlyForDeploymentPostprocessing = 0; 141 | }; 142 | /* End PBXResourcesBuildPhase section */ 143 | 144 | /* Begin PBXSourcesBuildPhase section */ 145 | 119C5BD322A635AA003EF04A /* Sources */ = { 146 | isa = PBXSourcesBuildPhase; 147 | buildActionMask = 2147483647; 148 | files = ( 149 | 119C5BDB22A635AA003EF04A /* AppDelegate.swift in Sources */, 150 | 119C5BDD22A635AA003EF04A /* SceneDelegate.swift in Sources */, 151 | 119C5BDF22A635AA003EF04A /* ContentView.swift in Sources */, 152 | ); 153 | runOnlyForDeploymentPostprocessing = 0; 154 | }; 155 | /* End PBXSourcesBuildPhase section */ 156 | 157 | /* Begin PBXVariantGroup section */ 158 | 119C5BE522A635AB003EF04A /* LaunchScreen.storyboard */ = { 159 | isa = PBXVariantGroup; 160 | children = ( 161 | 119C5BE622A635AB003EF04A /* Base */, 162 | ); 163 | name = LaunchScreen.storyboard; 164 | sourceTree = ""; 165 | }; 166 | /* End PBXVariantGroup section */ 167 | 168 | /* Begin XCBuildConfiguration section */ 169 | 119C5BE922A635AB003EF04A /* Debug */ = { 170 | isa = XCBuildConfiguration; 171 | buildSettings = { 172 | ALWAYS_SEARCH_USER_PATHS = NO; 173 | CLANG_ANALYZER_NONNULL = YES; 174 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 175 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 176 | CLANG_CXX_LIBRARY = "libc++"; 177 | CLANG_ENABLE_MODULES = YES; 178 | CLANG_ENABLE_OBJC_ARC = YES; 179 | CLANG_ENABLE_OBJC_WEAK = YES; 180 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 181 | CLANG_WARN_BOOL_CONVERSION = YES; 182 | CLANG_WARN_COMMA = YES; 183 | CLANG_WARN_CONSTANT_CONVERSION = YES; 184 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 185 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 186 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 187 | CLANG_WARN_EMPTY_BODY = YES; 188 | CLANG_WARN_ENUM_CONVERSION = YES; 189 | CLANG_WARN_INFINITE_RECURSION = YES; 190 | CLANG_WARN_INT_CONVERSION = YES; 191 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 192 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 193 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 194 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 195 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 196 | CLANG_WARN_STRICT_PROTOTYPES = YES; 197 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 198 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 199 | CLANG_WARN_UNREACHABLE_CODE = YES; 200 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 201 | COPY_PHASE_STRIP = NO; 202 | DEBUG_INFORMATION_FORMAT = dwarf; 203 | ENABLE_STRICT_OBJC_MSGSEND = YES; 204 | ENABLE_TESTABILITY = YES; 205 | GCC_C_LANGUAGE_STANDARD = gnu11; 206 | GCC_DYNAMIC_NO_PIC = NO; 207 | GCC_NO_COMMON_BLOCKS = YES; 208 | GCC_OPTIMIZATION_LEVEL = 0; 209 | GCC_PREPROCESSOR_DEFINITIONS = ( 210 | "DEBUG=1", 211 | "$(inherited)", 212 | ); 213 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 214 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 215 | GCC_WARN_UNDECLARED_SELECTOR = YES; 216 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 217 | GCC_WARN_UNUSED_FUNCTION = YES; 218 | GCC_WARN_UNUSED_VARIABLE = YES; 219 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 220 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 221 | MTL_FAST_MATH = YES; 222 | ONLY_ACTIVE_ARCH = YES; 223 | SDKROOT = iphoneos; 224 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 225 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 226 | }; 227 | name = Debug; 228 | }; 229 | 119C5BEA22A635AB003EF04A /* Release */ = { 230 | isa = XCBuildConfiguration; 231 | buildSettings = { 232 | ALWAYS_SEARCH_USER_PATHS = NO; 233 | CLANG_ANALYZER_NONNULL = YES; 234 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 235 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 236 | CLANG_CXX_LIBRARY = "libc++"; 237 | CLANG_ENABLE_MODULES = YES; 238 | CLANG_ENABLE_OBJC_ARC = YES; 239 | CLANG_ENABLE_OBJC_WEAK = YES; 240 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 241 | CLANG_WARN_BOOL_CONVERSION = YES; 242 | CLANG_WARN_COMMA = YES; 243 | CLANG_WARN_CONSTANT_CONVERSION = YES; 244 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 245 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 246 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 247 | CLANG_WARN_EMPTY_BODY = YES; 248 | CLANG_WARN_ENUM_CONVERSION = YES; 249 | CLANG_WARN_INFINITE_RECURSION = YES; 250 | CLANG_WARN_INT_CONVERSION = YES; 251 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 252 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 253 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 254 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 255 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 256 | CLANG_WARN_STRICT_PROTOTYPES = YES; 257 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 258 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 259 | CLANG_WARN_UNREACHABLE_CODE = YES; 260 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 261 | COPY_PHASE_STRIP = NO; 262 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 263 | ENABLE_NS_ASSERTIONS = NO; 264 | ENABLE_STRICT_OBJC_MSGSEND = YES; 265 | GCC_C_LANGUAGE_STANDARD = gnu11; 266 | GCC_NO_COMMON_BLOCKS = YES; 267 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 268 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 269 | GCC_WARN_UNDECLARED_SELECTOR = YES; 270 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 271 | GCC_WARN_UNUSED_FUNCTION = YES; 272 | GCC_WARN_UNUSED_VARIABLE = YES; 273 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 274 | MTL_ENABLE_DEBUG_INFO = NO; 275 | MTL_FAST_MATH = YES; 276 | SDKROOT = iphoneos; 277 | SWIFT_COMPILATION_MODE = wholemodule; 278 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 279 | VALIDATE_PRODUCT = YES; 280 | }; 281 | name = Release; 282 | }; 283 | 119C5BEC22A635AB003EF04A /* Debug */ = { 284 | isa = XCBuildConfiguration; 285 | buildSettings = { 286 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 287 | CODE_SIGN_STYLE = Automatic; 288 | DEVELOPMENT_ASSET_PATHS = "SwiftUI-example/Preview\\ Content"; 289 | DEVELOPMENT_TEAM = NL54V6A3P5; 290 | ENABLE_PREVIEWS = YES; 291 | INFOPLIST_FILE = "SwiftUI-example/Info.plist"; 292 | LD_RUNPATH_SEARCH_PATHS = ( 293 | "$(inherited)", 294 | "@executable_path/Frameworks", 295 | ); 296 | PRODUCT_BUNDLE_IDENTIFIER = "com.sinoroad.SwiftUI-example"; 297 | PRODUCT_NAME = "$(TARGET_NAME)"; 298 | SWIFT_VERSION = 5.0; 299 | TARGETED_DEVICE_FAMILY = "1,2"; 300 | }; 301 | name = Debug; 302 | }; 303 | 119C5BED22A635AB003EF04A /* Release */ = { 304 | isa = XCBuildConfiguration; 305 | buildSettings = { 306 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 307 | CODE_SIGN_STYLE = Automatic; 308 | DEVELOPMENT_ASSET_PATHS = "SwiftUI-example/Preview\\ Content"; 309 | DEVELOPMENT_TEAM = NL54V6A3P5; 310 | ENABLE_PREVIEWS = YES; 311 | INFOPLIST_FILE = "SwiftUI-example/Info.plist"; 312 | LD_RUNPATH_SEARCH_PATHS = ( 313 | "$(inherited)", 314 | "@executable_path/Frameworks", 315 | ); 316 | PRODUCT_BUNDLE_IDENTIFIER = "com.sinoroad.SwiftUI-example"; 317 | PRODUCT_NAME = "$(TARGET_NAME)"; 318 | SWIFT_VERSION = 5.0; 319 | TARGETED_DEVICE_FAMILY = "1,2"; 320 | }; 321 | name = Release; 322 | }; 323 | /* End XCBuildConfiguration section */ 324 | 325 | /* Begin XCConfigurationList section */ 326 | 119C5BD222A635AA003EF04A /* Build configuration list for PBXProject "SwiftUI-example" */ = { 327 | isa = XCConfigurationList; 328 | buildConfigurations = ( 329 | 119C5BE922A635AB003EF04A /* Debug */, 330 | 119C5BEA22A635AB003EF04A /* Release */, 331 | ); 332 | defaultConfigurationIsVisible = 0; 333 | defaultConfigurationName = Release; 334 | }; 335 | 119C5BEB22A635AB003EF04A /* Build configuration list for PBXNativeTarget "SwiftUI-example" */ = { 336 | isa = XCConfigurationList; 337 | buildConfigurations = ( 338 | 119C5BEC22A635AB003EF04A /* Debug */, 339 | 119C5BED22A635AB003EF04A /* Release */, 340 | ); 341 | defaultConfigurationIsVisible = 0; 342 | defaultConfigurationName = Release; 343 | }; 344 | /* End XCConfigurationList section */ 345 | }; 346 | rootObject = 119C5BCF22A635AA003EF04A /* Project object */; 347 | } 348 | -------------------------------------------------------------------------------- /SwiftUI-example/SwiftUI-example.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SwiftUI-example/SwiftUI-example.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /SwiftUI-example/SwiftUI-example.xcodeproj/project.xcworkspace/xcuserdata/zhudekun.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DKJone/SwiftUI-Learning/600993beb700a9100b83e8d6cc807ab94d06faf5/SwiftUI-example/SwiftUI-example.xcodeproj/project.xcworkspace/xcuserdata/zhudekun.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /SwiftUI-example/SwiftUI-example.xcodeproj/xcuserdata/zhudekun.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /SwiftUI-example/SwiftUI-example.xcodeproj/xcuserdata/zhudekun.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | SwiftUI-example.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /SwiftUI-example/SwiftUI-example/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // SwiftUI-example 4 | // 5 | // Created by 朱德坤 on 2019/6/4. 6 | // Copyright © 2019 DKJone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | 15 | 16 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 17 | // Override point for customization after application launch. 18 | return true 19 | } 20 | 21 | func applicationWillTerminate(_ application: UIApplication) { 22 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 23 | } 24 | 25 | // MARK: UISceneSession Lifecycle 26 | 27 | func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 28 | // Called when a new scene session is being created. 29 | // Use this method to select a configuration to create the new scene with. 30 | return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 31 | } 32 | 33 | func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { 34 | // Called when the user discards a scene session. 35 | // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 36 | // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 37 | } 38 | 39 | 40 | } 41 | 42 | -------------------------------------------------------------------------------- /SwiftUI-example/SwiftUI-example/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /SwiftUI-example/SwiftUI-example/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /SwiftUI-example/SwiftUI-example/Assets.xcassets/img.imageset/589c299564dbf.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DKJone/SwiftUI-Learning/600993beb700a9100b83e8d6cc807ab94d06faf5/SwiftUI-example/SwiftUI-example/Assets.xcassets/img.imageset/589c299564dbf.jpg -------------------------------------------------------------------------------- /SwiftUI-example/SwiftUI-example/Assets.xcassets/img.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "589c299564dbf.jpg", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /SwiftUI-example/SwiftUI-example/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /SwiftUI-example/SwiftUI-example/ContentView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContentView.swift 3 | // SwiftUI-example 4 | // 5 | // Created by 朱德坤 on 2019/6/4. 6 | // Copyright © 2019 DKJone. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | struct ContentView: View { 11 | var body: some View { 12 | // 创建 文本(Label) 13 | let aText = Text("Hello SwiftUI") 14 | .color(.yellow) 15 | .strikethrough() 16 | .font(.system(size: 14.1)) 17 | 18 | // 创建 按钮(Button) 19 | let aButton = Button(action: { 20 | print(#function) 21 | }) { 22 | Text("Hello SwiftUI") 23 | } 24 | 25 | let aView = AnyView(aText) 26 | 27 | // 创建图片 28 | let anImage = Image("img") 29 | .aspectRatio(contentMode: .fit) 30 | 31 | // 布局各视图 32 | return VStack { 33 | anImage 34 | aText 35 | aButton 36 | aView 37 | } 38 | } 39 | } 40 | 41 | #if DEBUG 42 | struct ContentView_Previews: PreviewProvider { 43 | static var previews: some View { 44 | ContentView() 45 | } 46 | } 47 | #endif 48 | -------------------------------------------------------------------------------- /SwiftUI-example/SwiftUI-example/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UIApplicationSceneManifest 24 | 25 | UIApplicationSupportsMultipleScenes 26 | 27 | UISceneConfigurations 28 | 29 | UIWindowSceneSessionRoleApplication 30 | 31 | 32 | UILaunchStoryboardName 33 | LaunchScreen 34 | UISceneConfigurationName 35 | Default Configuration 36 | UISceneDelegateClassName 37 | $(PRODUCT_MODULE_NAME).SceneDelegate 38 | 39 | 40 | 41 | 42 | UILaunchStoryboardName 43 | LaunchScreen 44 | UIRequiredDeviceCapabilities 45 | 46 | armv7 47 | 48 | UISupportedInterfaceOrientations 49 | 50 | UIInterfaceOrientationPortrait 51 | UIInterfaceOrientationLandscapeLeft 52 | UIInterfaceOrientationLandscapeRight 53 | 54 | UISupportedInterfaceOrientations~ipad 55 | 56 | UIInterfaceOrientationPortrait 57 | UIInterfaceOrientationPortraitUpsideDown 58 | UIInterfaceOrientationLandscapeLeft 59 | UIInterfaceOrientationLandscapeRight 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /SwiftUI-example/SwiftUI-example/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /SwiftUI-example/SwiftUI-example/SceneDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.swift 3 | // SwiftUI-example 4 | // 5 | // Created by 朱德坤 on 2019/6/4. 6 | // Copyright © 2019 DKJone. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import SwiftUI 11 | 12 | class SceneDelegate: UIResponder, UIWindowSceneDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { 18 | // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. 19 | // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. 20 | // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). 21 | 22 | // Use a UIHostingController as window root view controller 23 | let window = UIWindow(frame: UIScreen.main.bounds) 24 | window.rootViewController = UIHostingController(rootView: ContentView()) 25 | self.window = window 26 | window.makeKeyAndVisible() 27 | } 28 | 29 | func sceneDidDisconnect(_ scene: UIScene) { 30 | // Called as the scene is being released by the system. 31 | // This occurs shortly after the scene enters the background, or when its session is discarded. 32 | // Release any resources associated with this scene that can be re-created the next time the scene connects. 33 | // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead). 34 | } 35 | 36 | func sceneDidBecomeActive(_ scene: UIScene) { 37 | // Called when the scene has moved from an inactive state to an active state. 38 | // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. 39 | } 40 | 41 | func sceneWillResignActive(_ scene: UIScene) { 42 | // Called when the scene will move from an active state to an inactive state. 43 | // This may occur due to temporary interruptions (ex. an incoming phone call). 44 | } 45 | 46 | func sceneWillEnterForeground(_ scene: UIScene) { 47 | // Called as the scene transitions from the background to the foreground. 48 | // Use this method to undo the changes made on entering the background. 49 | } 50 | 51 | func sceneDidEnterBackground(_ scene: UIScene) { 52 | // Called as the scene transitions from the foreground to the background. 53 | // Use this method to save data, release shared resources, and store enough scene-specific state information 54 | // to restore the scene back to its current state. 55 | } 56 | 57 | 58 | } 59 | 60 | -------------------------------------------------------------------------------- /p1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DKJone/SwiftUI-Learning/600993beb700a9100b83e8d6cc807ab94d06faf5/p1.png -------------------------------------------------------------------------------- /p2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DKJone/SwiftUI-Learning/600993beb700a9100b83e8d6cc807ab94d06faf5/p2.png -------------------------------------------------------------------------------- /p3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DKJone/SwiftUI-Learning/600993beb700a9100b83e8d6cc807ab94d06faf5/p3.png -------------------------------------------------------------------------------- /p5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DKJone/SwiftUI-Learning/600993beb700a9100b83e8d6cc807ab94d06faf5/p5.png -------------------------------------------------------------------------------- /p6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DKJone/SwiftUI-Learning/600993beb700a9100b83e8d6cc807ab94d06faf5/p6.png -------------------------------------------------------------------------------- /p7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DKJone/SwiftUI-Learning/600993beb700a9100b83e8d6cc807ab94d06faf5/p7.png --------------------------------------------------------------------------------