├── README.md ├── iOS6Toggle.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcuserdata │ └── elvinhu.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist ├── iOS6Toggle ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── Base.lproj │ └── LaunchScreen.storyboard ├── ContentView.swift ├── Info.plist ├── Preview Content │ └── Preview Assets.xcassets │ │ └── Contents.json └── SceneDelegate.swift └── preview.gif /README.md: -------------------------------------------------------------------------------- 1 | # SwiftUI iOS 6 Style Toggle 2 | 3 | 4 | 5 | Please do not use this toggle in a "serious" project. 6 | 7 | I created this to demonstrate how far the drawing and graphics tools in SwiftUI can be pushed and what can be accomplished, but doing so brings forward many issues like accessibility concerns, etc. 8 | 9 | Got any questions? Tweet at me: @elvin_not_11 10 | -------------------------------------------------------------------------------- /iOS6Toggle.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | EE1DBA3623E9C90A00D22533 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE1DBA3523E9C90A00D22533 /* AppDelegate.swift */; }; 11 | EE1DBA3823E9C90A00D22533 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE1DBA3723E9C90A00D22533 /* SceneDelegate.swift */; }; 12 | EE1DBA3A23E9C90A00D22533 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE1DBA3923E9C90A00D22533 /* ContentView.swift */; }; 13 | EE1DBA3C23E9C90C00D22533 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EE1DBA3B23E9C90C00D22533 /* Assets.xcassets */; }; 14 | EE1DBA3F23E9C90C00D22533 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EE1DBA3E23E9C90C00D22533 /* Preview Assets.xcassets */; }; 15 | EE1DBA4223E9C90C00D22533 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = EE1DBA4023E9C90C00D22533 /* LaunchScreen.storyboard */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | EE1DBA3223E9C90A00D22533 /* iOS6Toggle.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iOS6Toggle.app; sourceTree = BUILT_PRODUCTS_DIR; }; 20 | EE1DBA3523E9C90A00D22533 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 21 | EE1DBA3723E9C90A00D22533 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 22 | EE1DBA3923E9C90A00D22533 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 23 | EE1DBA3B23E9C90C00D22533 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 24 | EE1DBA3E23E9C90C00D22533 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 25 | EE1DBA4123E9C90C00D22533 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 26 | EE1DBA4323E9C90C00D22533 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 27 | /* End PBXFileReference section */ 28 | 29 | /* Begin PBXFrameworksBuildPhase section */ 30 | EE1DBA2F23E9C90A00D22533 /* Frameworks */ = { 31 | isa = PBXFrameworksBuildPhase; 32 | buildActionMask = 2147483647; 33 | files = ( 34 | ); 35 | runOnlyForDeploymentPostprocessing = 0; 36 | }; 37 | /* End PBXFrameworksBuildPhase section */ 38 | 39 | /* Begin PBXGroup section */ 40 | EE1DBA2923E9C90A00D22533 = { 41 | isa = PBXGroup; 42 | children = ( 43 | EE1DBA3423E9C90A00D22533 /* iOS6Toggle */, 44 | EE1DBA3323E9C90A00D22533 /* Products */, 45 | ); 46 | sourceTree = ""; 47 | }; 48 | EE1DBA3323E9C90A00D22533 /* Products */ = { 49 | isa = PBXGroup; 50 | children = ( 51 | EE1DBA3223E9C90A00D22533 /* iOS6Toggle.app */, 52 | ); 53 | name = Products; 54 | sourceTree = ""; 55 | }; 56 | EE1DBA3423E9C90A00D22533 /* iOS6Toggle */ = { 57 | isa = PBXGroup; 58 | children = ( 59 | EE1DBA3523E9C90A00D22533 /* AppDelegate.swift */, 60 | EE1DBA3723E9C90A00D22533 /* SceneDelegate.swift */, 61 | EE1DBA3923E9C90A00D22533 /* ContentView.swift */, 62 | EE1DBA3B23E9C90C00D22533 /* Assets.xcassets */, 63 | EE1DBA4023E9C90C00D22533 /* LaunchScreen.storyboard */, 64 | EE1DBA4323E9C90C00D22533 /* Info.plist */, 65 | EE1DBA3D23E9C90C00D22533 /* Preview Content */, 66 | ); 67 | path = iOS6Toggle; 68 | sourceTree = ""; 69 | }; 70 | EE1DBA3D23E9C90C00D22533 /* Preview Content */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | EE1DBA3E23E9C90C00D22533 /* Preview Assets.xcassets */, 74 | ); 75 | path = "Preview Content"; 76 | sourceTree = ""; 77 | }; 78 | /* End PBXGroup section */ 79 | 80 | /* Begin PBXNativeTarget section */ 81 | EE1DBA3123E9C90A00D22533 /* iOS6Toggle */ = { 82 | isa = PBXNativeTarget; 83 | buildConfigurationList = EE1DBA4623E9C90C00D22533 /* Build configuration list for PBXNativeTarget "iOS6Toggle" */; 84 | buildPhases = ( 85 | EE1DBA2E23E9C90A00D22533 /* Sources */, 86 | EE1DBA2F23E9C90A00D22533 /* Frameworks */, 87 | EE1DBA3023E9C90A00D22533 /* Resources */, 88 | ); 89 | buildRules = ( 90 | ); 91 | dependencies = ( 92 | ); 93 | name = iOS6Toggle; 94 | productName = iOS6Toggle; 95 | productReference = EE1DBA3223E9C90A00D22533 /* iOS6Toggle.app */; 96 | productType = "com.apple.product-type.application"; 97 | }; 98 | /* End PBXNativeTarget section */ 99 | 100 | /* Begin PBXProject section */ 101 | EE1DBA2A23E9C90A00D22533 /* Project object */ = { 102 | isa = PBXProject; 103 | attributes = { 104 | LastSwiftUpdateCheck = 1130; 105 | LastUpgradeCheck = 1130; 106 | ORGANIZATIONNAME = "Elvin Hu"; 107 | TargetAttributes = { 108 | EE1DBA3123E9C90A00D22533 = { 109 | CreatedOnToolsVersion = 11.3; 110 | }; 111 | }; 112 | }; 113 | buildConfigurationList = EE1DBA2D23E9C90A00D22533 /* Build configuration list for PBXProject "iOS6Toggle" */; 114 | compatibilityVersion = "Xcode 9.3"; 115 | developmentRegion = en; 116 | hasScannedForEncodings = 0; 117 | knownRegions = ( 118 | en, 119 | Base, 120 | ); 121 | mainGroup = EE1DBA2923E9C90A00D22533; 122 | productRefGroup = EE1DBA3323E9C90A00D22533 /* Products */; 123 | projectDirPath = ""; 124 | projectRoot = ""; 125 | targets = ( 126 | EE1DBA3123E9C90A00D22533 /* iOS6Toggle */, 127 | ); 128 | }; 129 | /* End PBXProject section */ 130 | 131 | /* Begin PBXResourcesBuildPhase section */ 132 | EE1DBA3023E9C90A00D22533 /* Resources */ = { 133 | isa = PBXResourcesBuildPhase; 134 | buildActionMask = 2147483647; 135 | files = ( 136 | EE1DBA4223E9C90C00D22533 /* LaunchScreen.storyboard in Resources */, 137 | EE1DBA3F23E9C90C00D22533 /* Preview Assets.xcassets in Resources */, 138 | EE1DBA3C23E9C90C00D22533 /* Assets.xcassets in Resources */, 139 | ); 140 | runOnlyForDeploymentPostprocessing = 0; 141 | }; 142 | /* End PBXResourcesBuildPhase section */ 143 | 144 | /* Begin PBXSourcesBuildPhase section */ 145 | EE1DBA2E23E9C90A00D22533 /* Sources */ = { 146 | isa = PBXSourcesBuildPhase; 147 | buildActionMask = 2147483647; 148 | files = ( 149 | EE1DBA3623E9C90A00D22533 /* AppDelegate.swift in Sources */, 150 | EE1DBA3823E9C90A00D22533 /* SceneDelegate.swift in Sources */, 151 | EE1DBA3A23E9C90A00D22533 /* ContentView.swift in Sources */, 152 | ); 153 | runOnlyForDeploymentPostprocessing = 0; 154 | }; 155 | /* End PBXSourcesBuildPhase section */ 156 | 157 | /* Begin PBXVariantGroup section */ 158 | EE1DBA4023E9C90C00D22533 /* LaunchScreen.storyboard */ = { 159 | isa = PBXVariantGroup; 160 | children = ( 161 | EE1DBA4123E9C90C00D22533 /* Base */, 162 | ); 163 | name = LaunchScreen.storyboard; 164 | sourceTree = ""; 165 | }; 166 | /* End PBXVariantGroup section */ 167 | 168 | /* Begin XCBuildConfiguration section */ 169 | EE1DBA4423E9C90C00D22533 /* 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.2; 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 | EE1DBA4523E9C90C00D22533 /* 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.2; 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 | EE1DBA4723E9C90C00D22533 /* Debug */ = { 284 | isa = XCBuildConfiguration; 285 | buildSettings = { 286 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 287 | CODE_SIGN_STYLE = Automatic; 288 | DEVELOPMENT_ASSET_PATHS = "\"iOS6Toggle/Preview Content\""; 289 | DEVELOPMENT_TEAM = XHLL669QU9; 290 | ENABLE_PREVIEWS = YES; 291 | INFOPLIST_FILE = iOS6Toggle/Info.plist; 292 | LD_RUNPATH_SEARCH_PATHS = ( 293 | "$(inherited)", 294 | "@executable_path/Frameworks", 295 | ); 296 | PRODUCT_BUNDLE_IDENTIFIER = "com.elvin-hu.iOS6Toggle"; 297 | PRODUCT_NAME = "$(TARGET_NAME)"; 298 | SWIFT_VERSION = 5.0; 299 | TARGETED_DEVICE_FAMILY = 1; 300 | }; 301 | name = Debug; 302 | }; 303 | EE1DBA4823E9C90C00D22533 /* Release */ = { 304 | isa = XCBuildConfiguration; 305 | buildSettings = { 306 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 307 | CODE_SIGN_STYLE = Automatic; 308 | DEVELOPMENT_ASSET_PATHS = "\"iOS6Toggle/Preview Content\""; 309 | DEVELOPMENT_TEAM = XHLL669QU9; 310 | ENABLE_PREVIEWS = YES; 311 | INFOPLIST_FILE = iOS6Toggle/Info.plist; 312 | LD_RUNPATH_SEARCH_PATHS = ( 313 | "$(inherited)", 314 | "@executable_path/Frameworks", 315 | ); 316 | PRODUCT_BUNDLE_IDENTIFIER = "com.elvin-hu.iOS6Toggle"; 317 | PRODUCT_NAME = "$(TARGET_NAME)"; 318 | SWIFT_VERSION = 5.0; 319 | TARGETED_DEVICE_FAMILY = 1; 320 | }; 321 | name = Release; 322 | }; 323 | /* End XCBuildConfiguration section */ 324 | 325 | /* Begin XCConfigurationList section */ 326 | EE1DBA2D23E9C90A00D22533 /* Build configuration list for PBXProject "iOS6Toggle" */ = { 327 | isa = XCConfigurationList; 328 | buildConfigurations = ( 329 | EE1DBA4423E9C90C00D22533 /* Debug */, 330 | EE1DBA4523E9C90C00D22533 /* Release */, 331 | ); 332 | defaultConfigurationIsVisible = 0; 333 | defaultConfigurationName = Release; 334 | }; 335 | EE1DBA4623E9C90C00D22533 /* Build configuration list for PBXNativeTarget "iOS6Toggle" */ = { 336 | isa = XCConfigurationList; 337 | buildConfigurations = ( 338 | EE1DBA4723E9C90C00D22533 /* Debug */, 339 | EE1DBA4823E9C90C00D22533 /* Release */, 340 | ); 341 | defaultConfigurationIsVisible = 0; 342 | defaultConfigurationName = Release; 343 | }; 344 | /* End XCConfigurationList section */ 345 | }; 346 | rootObject = EE1DBA2A23E9C90A00D22533 /* Project object */; 347 | } 348 | -------------------------------------------------------------------------------- /iOS6Toggle.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /iOS6Toggle.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /iOS6Toggle.xcodeproj/xcuserdata/elvinhu.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | iOS6Toggle.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /iOS6Toggle/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // iOS6Toggle 4 | // 5 | // Created by Elvin Hu on 2/4/20. 6 | // Copyright © 2020 Elvin Hu. 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 | // MARK: UISceneSession Lifecycle 22 | 23 | func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 24 | // Called when a new scene session is being created. 25 | // Use this method to select a configuration to create the new scene with. 26 | return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 27 | } 28 | 29 | func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { 30 | // Called when the user discards a scene session. 31 | // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 32 | // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 33 | } 34 | 35 | 36 | } 37 | 38 | -------------------------------------------------------------------------------- /iOS6Toggle/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 | } -------------------------------------------------------------------------------- /iOS6Toggle/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /iOS6Toggle/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 | -------------------------------------------------------------------------------- /iOS6Toggle/ContentView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContentView.swift 3 | // iOS6Toggle 4 | // 5 | // Created by Elvin Hu on 2/4/20. 6 | // Copyright © 2020 Elvin Hu. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | 11 | struct ContentView: View { 12 | /// Wheter the toggle is on or not. 13 | @State var isOn: Bool = false 14 | /// The toggle should hide the blue background when it isn't on, but show the blue background otherwise. 15 | /// When the knob is being dragged from off to on, the blue background should show up right away and move with it. 16 | @State var shouldShowBlueBackground: Bool = false 17 | /// Displacement of the knob. 18 | @State var viewDisplacement = CGSize.zero 19 | 20 | var body: some View { 21 | ZStack { 22 | // Toggle white background - stays still 23 | RoundedRectangle(cornerRadius: 16) 24 | .fill(Color(red: 247/255, green: 247/255, blue: 247/255)) 25 | .frame(width: 92, height: 32) 26 | 27 | // OFF Text 28 | Text("OFF") 29 | .font(.system(size: 18, weight: .bold)) 30 | .foregroundColor(Color(red: 111/255, green: 111/255, blue: 111/255)) 31 | .shadow(color: Color(red: 1, green: 1, blue: 1, opacity: 1), radius: 0, x: 0, y: -1) 32 | // The "OFF" text appears at the center of the toggle on default without any offset (as SwiftUI prefer to center contents), 33 | // to make sure it appears on the center of the toggle background area (the white area), 34 | // it has has a 10 pixels of horizontal offset while the toggle is off, 35 | // and it will move to the right, out of the visible area when the toggle is on. 36 | .offset(x: isOn ? 70 : 10) 37 | //viewDisplacement controls the horizontal offset of the UI elements as the user performs the drag gesture 38 | .offset(x: viewDisplacement.width) 39 | 40 | // Toggle blue background - moves with the gesture 41 | RoundedRectangle(cornerRadius: 16) 42 | .fill(Color(red: 4/255, green: 125/255, blue: 229/255)) 43 | .frame(width: 92, height: 32) 44 | .offset(x: isOn ? 0 : -60) 45 | .offset(x: viewDisplacement.width) 46 | .opacity(shouldShowBlueBackground ? 1 : 0) 47 | 48 | // ON Text 49 | Text("ON") 50 | .font(.system(size: 18, weight: .bold)) 51 | .foregroundColor(Color.white) 52 | .shadow(color: Color(red: 0, green: 0, blue: 0, opacity: 0.3), radius: 0, x: 0, y: -1) 53 | // similar behavior as the "OFF" text 54 | .offset(x: isOn ? -10 : -70) 55 | .offset(x: viewDisplacement.width) 56 | 57 | // Toggle highlight - stays still 58 | RoundedRectangle(cornerRadius: 12) 59 | .fill( 60 | LinearGradient( 61 | gradient: Gradient( 62 | colors: [Color(.sRGB, red: 1, green: 1, blue: 1, opacity: 0.10), 63 | Color(.sRGB, red: 1, green: 1, blue: 1, opacity: 0.70)]), 64 | startPoint: .top, 65 | endPoint: .bottom 66 | ) 67 | ) 68 | .frame(width: 80, height: 24) 69 | .offset(y: 12) 70 | 71 | // Toggle shadow - stays still 72 | RoundedRectangle(cornerRadius: 16) 73 | .stroke(Color.black, lineWidth: 0.5) 74 | .blur(radius: 0.5) 75 | .frame(width: 92, height: 32) 76 | .mask( 77 | RoundedRectangle(cornerRadius: 16) 78 | .frame(width: 92, height: 32) 79 | ) 80 | // Top inner shadow 81 | .overlay( 82 | RoundedRectangle(cornerRadius: 16) 83 | .stroke(Color.gray, lineWidth: 2) 84 | .blur(radius: 2) 85 | .frame(width: 92, height: 32) 86 | .offset(y: 1.5) 87 | // Create a natural fall-off for the top shadow 88 | .mask( 89 | RoundedRectangle(cornerRadius: 16) 90 | .fill( 91 | LinearGradient( 92 | gradient: Gradient( 93 | colors: [Color(.sRGB, red: 0, green: 0, blue: 0, opacity: 1), 94 | Color(.sRGB, red: 0, green: 0, blue: 0, opacity: 0)]), 95 | startPoint: .top, 96 | endPoint: .bottom 97 | ) 98 | ) 99 | .frame(width: 92, height: 32) 100 | 101 | ) 102 | // Set blend mode to multiply so the inner shadow reflects what color is underneath it 103 | .blendMode(.multiply) 104 | ) 105 | .opacity(0.9) 106 | 107 | // Toggle knob - moves with the gesture 108 | Button(action: { 109 | withAnimation(.easeInOut(duration: 0.25)){ 110 | self.isOn.toggle() 111 | } 112 | if self.isOn { 113 | self.shouldShowBlueBackground = true 114 | } else { 115 | withAnimation(Animation.easeInOut(duration: 0.25).delay(0.125)) { 116 | self.shouldShowBlueBackground = false 117 | } 118 | } 119 | }){ 120 | Circle() 121 | .fill(LinearGradient( 122 | gradient: Gradient( 123 | colors: [Color(red: 214/255, green: 213/255, blue: 211/255), 124 | Color(red: 252/255, green: 252/255, blue: 251/255)]), 125 | startPoint: .top, 126 | endPoint: .bottom 127 | ) 128 | ) 129 | // Two layers of shadow 130 | .shadow(radius: 2) 131 | .shadow(radius: 0.5) 132 | .overlay( 133 | // Blur then mask a circular stroke view for the inner shadow/stroke effect 134 | Circle() 135 | .stroke(Color.white, lineWidth: 2) 136 | .blur(radius: 0.5) 137 | // Hide the 138 | .mask(Circle()) 139 | ) 140 | 141 | .offset(x: viewDisplacement.width) 142 | .offset(x: isOn ? 30: -30) 143 | .frame(width: 30, height: 30) 144 | } 145 | } 146 | .mask( 147 | RoundedRectangle(cornerRadius: 16) 148 | .fill(Color(red: 247/255, green: 247/255, blue: 247/255)) 149 | .frame(width: 92, height: 32) 150 | ) 151 | // Use .highPriorityGesture to make sure the drag gesture is captured before the default tap gesture of the button 152 | .highPriorityGesture( 153 | DragGesture().onChanged { value in 154 | self.shouldShowBlueBackground = true 155 | // If the toggle is off (gray) before the user perform the gesture 156 | if !self.isOn { 157 | // If the toggle is being dragged to the left (negative value in horizontal offset), nothing should move 158 | if value.translation.width < 0 { 159 | self.viewDisplacement = .zero 160 | } 161 | // Once the knob is dragged from the left end to the right end, the UI elements should stop moving 162 | else if value.translation.width > 60 { 163 | self.viewDisplacement.width = 60 164 | } 165 | // If the knob is between the left end and the right end, assign the current translation of the gesture to viewDisplacement, 166 | // so the UI elements would move along with the gesture. 167 | else { 168 | self.viewDisplacement = value.translation 169 | } 170 | } 171 | // If the toggle is on (blue) before the user perform the gesture 172 | else { 173 | // If the toggle is being dragged to the right (positive value in horizontal offset), nothing should move 174 | if value.translation.width > 0 { 175 | self.viewDisplacement = .zero 176 | } 177 | // Once the knob is dragged from the right end to the left end, the UI elements should stop moving 178 | else if value.translation.width < -60 { 179 | self.viewDisplacement.width = -60 180 | } 181 | // If the knob is between the left end and the right end, assign the current translation of the gesture to viewDisplacement 182 | // so the UI elements would move along with the gesture. 183 | else { 184 | self.viewDisplacement = value.translation 185 | } 186 | } 187 | } 188 | .onEnded { value in 189 | withAnimation(.easeInOut(duration: 0.25)) { 190 | // If the knob is dragged for a distance longer than half of the width of the toggle, change the state of the toggle 191 | if !self.isOn && value.translation.width > 30 || self.isOn && value.translation.width < -30 { 192 | self.isOn.toggle() 193 | } 194 | // Reset the position of the toggle to its new default position after the change of state 195 | self.viewDisplacement = .zero 196 | } 197 | // Hide the blue background if the toggle is off at the end of the gesture, so that there wouldn't be a blue stroke/halo around the knob visible 198 | if !self.isOn { 199 | withAnimation(Animation.easeInOut(duration: 0.25).delay(0.125)) { 200 | self.shouldShowBlueBackground = false 201 | } 202 | } 203 | } 204 | ) 205 | } 206 | } 207 | 208 | struct ContentView_Previews: PreviewProvider { 209 | static var previews: some View { 210 | ContentView() 211 | } 212 | } 213 | -------------------------------------------------------------------------------- /iOS6Toggle/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 | UISceneConfigurationName 33 | Default Configuration 34 | UISceneDelegateClassName 35 | $(PRODUCT_MODULE_NAME).SceneDelegate 36 | 37 | 38 | 39 | 40 | UILaunchStoryboardName 41 | LaunchScreen 42 | UIRequiredDeviceCapabilities 43 | 44 | armv7 45 | 46 | UISupportedInterfaceOrientations 47 | 48 | UIInterfaceOrientationPortrait 49 | UIInterfaceOrientationLandscapeLeft 50 | UIInterfaceOrientationLandscapeRight 51 | 52 | UISupportedInterfaceOrientations~ipad 53 | 54 | UIInterfaceOrientationPortrait 55 | UIInterfaceOrientationPortraitUpsideDown 56 | UIInterfaceOrientationLandscapeLeft 57 | UIInterfaceOrientationLandscapeRight 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /iOS6Toggle/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /iOS6Toggle/SceneDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.swift 3 | // iOS6Toggle 4 | // 5 | // Created by Elvin Hu on 2/4/20. 6 | // Copyright © 2020 Elvin Hu. 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 | // Create the SwiftUI view that provides the window contents. 23 | let contentView = ContentView() 24 | 25 | // Use a UIHostingController as window root view controller. 26 | if let windowScene = scene as? UIWindowScene { 27 | let window = UIWindow(windowScene: windowScene) 28 | window.rootViewController = UIHostingController(rootView: contentView) 29 | self.window = window 30 | window.makeKeyAndVisible() 31 | } 32 | } 33 | 34 | func sceneDidDisconnect(_ scene: UIScene) { 35 | // Called as the scene is being released by the system. 36 | // This occurs shortly after the scene enters the background, or when its session is discarded. 37 | // Release any resources associated with this scene that can be re-created the next time the scene connects. 38 | // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead). 39 | } 40 | 41 | func sceneDidBecomeActive(_ scene: UIScene) { 42 | // Called when the scene has moved from an inactive state to an active state. 43 | // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. 44 | } 45 | 46 | func sceneWillResignActive(_ scene: UIScene) { 47 | // Called when the scene will move from an active state to an inactive state. 48 | // This may occur due to temporary interruptions (ex. an incoming phone call). 49 | } 50 | 51 | func sceneWillEnterForeground(_ scene: UIScene) { 52 | // Called as the scene transitions from the background to the foreground. 53 | // Use this method to undo the changes made on entering the background. 54 | } 55 | 56 | func sceneDidEnterBackground(_ scene: UIScene) { 57 | // Called as the scene transitions from the foreground to the background. 58 | // Use this method to save data, release shared resources, and store enough scene-specific state information 59 | // to restore the scene back to its current state. 60 | } 61 | 62 | 63 | } 64 | 65 | -------------------------------------------------------------------------------- /preview.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elvin-hu/SwiftUIiOS6Toggle/5f10aed9739ebf862c3af37bdd96a61914086117/preview.gif --------------------------------------------------------------------------------