├── .gitignore ├── .swift-version ├── LICENSE ├── NSSwitch.podspec ├── NSSwitch.xcodeproj ├── project.pbxproj └── xcshareddata │ └── xcschemes │ └── NSSwitch.xcscheme ├── NSSwitch ├── Info.plist ├── NSSwitch.h ├── NSSwitch.swift └── NSSwitchThumbView.swift ├── NSSwitchDemo ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ └── Main.storyboard ├── Info.plist ├── NSSwitchDemo.entitlements └── ViewController.swift ├── NSSwitch_screenshot.png └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.DS_Store 2 | # Created by https://www.gitignore.io/api/swift,xcode 3 | 4 | ### Swift ### 5 | # Xcode 6 | # 7 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 8 | 9 | ## Build generated 10 | build/ 11 | DerivedData/ 12 | 13 | ## Various settings 14 | *.pbxuser 15 | !default.pbxuser 16 | *.mode1v3 17 | !default.mode1v3 18 | *.mode2v3 19 | !default.mode2v3 20 | *.perspectivev3 21 | !default.perspectivev3 22 | xcuserdata/ 23 | 24 | ## Other 25 | *.moved-aside 26 | *.xccheckout 27 | *.xcscmblueprint 28 | 29 | ## Obj-C/Swift specific 30 | *.hmap 31 | *.ipa 32 | *.dSYM.zip 33 | *.dSYM 34 | 35 | ## Playgrounds 36 | timeline.xctimeline 37 | playground.xcworkspace 38 | 39 | # Swift Package Manager 40 | # 41 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 42 | # Packages/ 43 | # Package.pins 44 | .build/ 45 | 46 | # CocoaPods - Refactored to standalone file 47 | 48 | # Carthage - Refactored to standalone file 49 | 50 | # fastlane 51 | # 52 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 53 | # screenshots whenever they are needed. 54 | # For more information about the recommended setup visit: 55 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 56 | 57 | fastlane/report.xml 58 | fastlane/Preview.html 59 | fastlane/screenshots 60 | fastlane/test_output 61 | 62 | ### Xcode ### 63 | # Xcode 64 | # 65 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 66 | 67 | ## Build generated 68 | 69 | ## Various settings 70 | 71 | ## Other 72 | 73 | ### Xcode Patch ### 74 | *.xcodeproj/* 75 | !*.xcodeproj/project.pbxproj 76 | !*.xcodeproj/xcshareddata/ 77 | !*.xcworkspace/contents.xcworkspacedata 78 | /*.gcno 79 | 80 | # End of https://www.gitignore.io/api/swift,xcode 81 | -------------------------------------------------------------------------------- /.swift-version: -------------------------------------------------------------------------------- 1 | 4.0 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017 Hayden Pennington 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /NSSwitch.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # Be sure to run `pod lib lint NSSwitch.podspec' to ensure this is a 3 | # valid spec before submitting. 4 | # 5 | # Any lines starting with a # are optional, but their use is encouraged 6 | # To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html 7 | # 8 | 9 | Pod::Spec.new do |s| 10 | s.name = 'NSSwitch' 11 | s.version = '1.1.4' 12 | s.summary = 'UISwitch for macOS.' 13 | 14 | # This description is used to generate tags and improve search results. 15 | # * Think: What does it do? Why did you write it? What is the focus? 16 | # * Try to keep it short, snappy and to the point. 17 | # * Write the description between the DESC delimiters below. 18 | # * Finally, don't worry about the indent, CocoaPods strips it! 19 | 20 | s.description = <<-DESC 21 | TODO: Add long description of the pod here. 22 | DESC 23 | 24 | s.homepage = 'https://github.com/hpennington/NSSwitch' 25 | # s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2' 26 | s.license = { :type => 'MIT', :file => 'LICENSE' } 27 | s.author = { 'haydenpennington@icloud.com' => 'haydenpennington@icloud.com' } 28 | s.source = { :git => 'https://github.com/hpennington/NSSwitch.git', :tag => s.version.to_s } 29 | # s.social_media_url = 'https://twitter.com/' 30 | 31 | s.osx.deployment_target = '10.10' 32 | 33 | s.source_files = 'NSSwitch/*.swift' 34 | 35 | # s.resource_bundles = { 36 | # 't' => ['t/Assets/*.png'] 37 | # } 38 | 39 | # s.public_header_files = 'Pod/Classes/**/*.h' 40 | # s.frameworks = 'UIKit', 'MapKit' 41 | # s.dependency 'AFNetworking', '~> 2.3' 42 | end 43 | -------------------------------------------------------------------------------- /NSSwitch.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 48; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | F8A148251FA281C50099271B /* NSSwitch.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8A148231FA281BD0099271B /* NSSwitch.swift */; }; 11 | F8A148261FA281C80099271B /* NSSwitchThumbView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8A148241FA281BD0099271B /* NSSwitchThumbView.swift */; }; 12 | F8FE2DBF1FA2C8C7004F4E5C /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8FE2DBE1FA2C8C7004F4E5C /* AppDelegate.swift */; }; 13 | F8FE2DC11FA2C8C7004F4E5C /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8FE2DC01FA2C8C7004F4E5C /* ViewController.swift */; }; 14 | F8FE2DC31FA2C8C7004F4E5C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F8FE2DC21FA2C8C7004F4E5C /* Assets.xcassets */; }; 15 | F8FE2DC61FA2C8C7004F4E5C /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F8FE2DC41FA2C8C7004F4E5C /* Main.storyboard */; }; 16 | F8FE2DCF1FA2CC19004F4E5C /* NSSwitch.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8A148041FA2809D0099271B /* NSSwitch.framework */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXContainerItemProxy section */ 20 | F8FE2DCC1FA2C8DF004F4E5C /* PBXContainerItemProxy */ = { 21 | isa = PBXContainerItemProxy; 22 | containerPortal = F8A147FB1FA2809D0099271B /* Project object */; 23 | proxyType = 1; 24 | remoteGlobalIDString = F8A148031FA2809D0099271B; 25 | remoteInfo = NSSwitch; 26 | }; 27 | /* End PBXContainerItemProxy section */ 28 | 29 | /* Begin PBXFileReference section */ 30 | F8A148041FA2809D0099271B /* NSSwitch.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = NSSwitch.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 31 | F8A1481E1FA2816C0099271B /* LICENSE */ = {isa = PBXFileReference; lastKnownFileType = text; path = LICENSE; sourceTree = ""; }; 32 | F8A1481F1FA2816C0099271B /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; 33 | F8A148231FA281BD0099271B /* NSSwitch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSSwitch.swift; sourceTree = ""; }; 34 | F8A148241FA281BD0099271B /* NSSwitchThumbView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSSwitchThumbView.swift; sourceTree = ""; }; 35 | F8FE2DB11FA28BFE004F4E5C /* NSSwitch.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NSSwitch.h; sourceTree = ""; }; 36 | F8FE2DB61FA28C5B004F4E5C /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 37 | F8FE2DBC1FA2C8C7004F4E5C /* NSSwitchDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NSSwitchDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 38 | F8FE2DBE1FA2C8C7004F4E5C /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 39 | F8FE2DC01FA2C8C7004F4E5C /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 40 | F8FE2DC21FA2C8C7004F4E5C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 41 | F8FE2DC51FA2C8C7004F4E5C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 42 | F8FE2DC71FA2C8C7004F4E5C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 43 | F8FE2DC81FA2C8C7004F4E5C /* NSSwitchDemo.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = NSSwitchDemo.entitlements; sourceTree = ""; }; 44 | /* End PBXFileReference section */ 45 | 46 | /* Begin PBXFrameworksBuildPhase section */ 47 | F8A148001FA2809D0099271B /* Frameworks */ = { 48 | isa = PBXFrameworksBuildPhase; 49 | buildActionMask = 2147483647; 50 | files = ( 51 | ); 52 | runOnlyForDeploymentPostprocessing = 0; 53 | }; 54 | F8FE2DB91FA2C8C7004F4E5C /* Frameworks */ = { 55 | isa = PBXFrameworksBuildPhase; 56 | buildActionMask = 2147483647; 57 | files = ( 58 | F8FE2DCF1FA2CC19004F4E5C /* NSSwitch.framework in Frameworks */, 59 | ); 60 | runOnlyForDeploymentPostprocessing = 0; 61 | }; 62 | /* End PBXFrameworksBuildPhase section */ 63 | 64 | /* Begin PBXGroup section */ 65 | F8A147FA1FA2809D0099271B = { 66 | isa = PBXGroup; 67 | children = ( 68 | F8A1481E1FA2816C0099271B /* LICENSE */, 69 | F8A1481F1FA2816C0099271B /* README.md */, 70 | F8A148061FA2809D0099271B /* NSSwitch */, 71 | F8FE2DBD1FA2C8C7004F4E5C /* NSSwitchDemo */, 72 | F8A148051FA2809D0099271B /* Products */, 73 | ); 74 | sourceTree = ""; 75 | }; 76 | F8A148051FA2809D0099271B /* Products */ = { 77 | isa = PBXGroup; 78 | children = ( 79 | F8A148041FA2809D0099271B /* NSSwitch.framework */, 80 | F8FE2DBC1FA2C8C7004F4E5C /* NSSwitchDemo.app */, 81 | ); 82 | name = Products; 83 | sourceTree = ""; 84 | }; 85 | F8A148061FA2809D0099271B /* NSSwitch */ = { 86 | isa = PBXGroup; 87 | children = ( 88 | F8FE2DB61FA28C5B004F4E5C /* Info.plist */, 89 | F8A148231FA281BD0099271B /* NSSwitch.swift */, 90 | F8A148241FA281BD0099271B /* NSSwitchThumbView.swift */, 91 | F8FE2DB11FA28BFE004F4E5C /* NSSwitch.h */, 92 | ); 93 | path = NSSwitch; 94 | sourceTree = ""; 95 | }; 96 | F8FE2DBD1FA2C8C7004F4E5C /* NSSwitchDemo */ = { 97 | isa = PBXGroup; 98 | children = ( 99 | F8FE2DBE1FA2C8C7004F4E5C /* AppDelegate.swift */, 100 | F8FE2DC01FA2C8C7004F4E5C /* ViewController.swift */, 101 | F8FE2DC21FA2C8C7004F4E5C /* Assets.xcassets */, 102 | F8FE2DC41FA2C8C7004F4E5C /* Main.storyboard */, 103 | F8FE2DC71FA2C8C7004F4E5C /* Info.plist */, 104 | F8FE2DC81FA2C8C7004F4E5C /* NSSwitchDemo.entitlements */, 105 | ); 106 | path = NSSwitchDemo; 107 | sourceTree = ""; 108 | }; 109 | /* End PBXGroup section */ 110 | 111 | /* Begin PBXHeadersBuildPhase section */ 112 | F8A148011FA2809D0099271B /* Headers */ = { 113 | isa = PBXHeadersBuildPhase; 114 | buildActionMask = 2147483647; 115 | files = ( 116 | ); 117 | runOnlyForDeploymentPostprocessing = 0; 118 | }; 119 | /* End PBXHeadersBuildPhase section */ 120 | 121 | /* Begin PBXNativeTarget section */ 122 | F8A148031FA2809D0099271B /* NSSwitch */ = { 123 | isa = PBXNativeTarget; 124 | buildConfigurationList = F8A148181FA2809D0099271B /* Build configuration list for PBXNativeTarget "NSSwitch" */; 125 | buildPhases = ( 126 | F8A147FF1FA2809D0099271B /* Sources */, 127 | F8A148001FA2809D0099271B /* Frameworks */, 128 | F8A148011FA2809D0099271B /* Headers */, 129 | F8A148021FA2809D0099271B /* Resources */, 130 | ); 131 | buildRules = ( 132 | ); 133 | dependencies = ( 134 | ); 135 | name = NSSwitch; 136 | productName = NSSwitch; 137 | productReference = F8A148041FA2809D0099271B /* NSSwitch.framework */; 138 | productType = "com.apple.product-type.framework"; 139 | }; 140 | F8FE2DBB1FA2C8C7004F4E5C /* NSSwitchDemo */ = { 141 | isa = PBXNativeTarget; 142 | buildConfigurationList = F8FE2DCB1FA2C8C7004F4E5C /* Build configuration list for PBXNativeTarget "NSSwitchDemo" */; 143 | buildPhases = ( 144 | F8FE2DB81FA2C8C7004F4E5C /* Sources */, 145 | F8FE2DB91FA2C8C7004F4E5C /* Frameworks */, 146 | F8FE2DBA1FA2C8C7004F4E5C /* Resources */, 147 | ); 148 | buildRules = ( 149 | ); 150 | dependencies = ( 151 | F8FE2DCD1FA2C8DF004F4E5C /* PBXTargetDependency */, 152 | ); 153 | name = NSSwitchDemo; 154 | productName = NSSwitchDemo; 155 | productReference = F8FE2DBC1FA2C8C7004F4E5C /* NSSwitchDemo.app */; 156 | productType = "com.apple.product-type.application"; 157 | }; 158 | /* End PBXNativeTarget section */ 159 | 160 | /* Begin PBXProject section */ 161 | F8A147FB1FA2809D0099271B /* Project object */ = { 162 | isa = PBXProject; 163 | attributes = { 164 | LastSwiftUpdateCheck = 0900; 165 | LastUpgradeCheck = 0900; 166 | ORGANIZATIONNAME = "Hayden Pennington"; 167 | TargetAttributes = { 168 | F8A148031FA2809D0099271B = { 169 | CreatedOnToolsVersion = 9.0.1; 170 | ProvisioningStyle = Automatic; 171 | }; 172 | F8FE2DBB1FA2C8C7004F4E5C = { 173 | CreatedOnToolsVersion = 9.0.1; 174 | ProvisioningStyle = Automatic; 175 | }; 176 | }; 177 | }; 178 | buildConfigurationList = F8A147FE1FA2809D0099271B /* Build configuration list for PBXProject "NSSwitch" */; 179 | compatibilityVersion = "Xcode 8.0"; 180 | developmentRegion = en; 181 | hasScannedForEncodings = 0; 182 | knownRegions = ( 183 | en, 184 | Base, 185 | ); 186 | mainGroup = F8A147FA1FA2809D0099271B; 187 | productRefGroup = F8A148051FA2809D0099271B /* Products */; 188 | projectDirPath = ""; 189 | projectRoot = ""; 190 | targets = ( 191 | F8A148031FA2809D0099271B /* NSSwitch */, 192 | F8FE2DBB1FA2C8C7004F4E5C /* NSSwitchDemo */, 193 | ); 194 | }; 195 | /* End PBXProject section */ 196 | 197 | /* Begin PBXResourcesBuildPhase section */ 198 | F8A148021FA2809D0099271B /* Resources */ = { 199 | isa = PBXResourcesBuildPhase; 200 | buildActionMask = 2147483647; 201 | files = ( 202 | ); 203 | runOnlyForDeploymentPostprocessing = 0; 204 | }; 205 | F8FE2DBA1FA2C8C7004F4E5C /* Resources */ = { 206 | isa = PBXResourcesBuildPhase; 207 | buildActionMask = 2147483647; 208 | files = ( 209 | F8FE2DC31FA2C8C7004F4E5C /* Assets.xcassets in Resources */, 210 | F8FE2DC61FA2C8C7004F4E5C /* Main.storyboard in Resources */, 211 | ); 212 | runOnlyForDeploymentPostprocessing = 0; 213 | }; 214 | /* End PBXResourcesBuildPhase section */ 215 | 216 | /* Begin PBXSourcesBuildPhase section */ 217 | F8A147FF1FA2809D0099271B /* Sources */ = { 218 | isa = PBXSourcesBuildPhase; 219 | buildActionMask = 2147483647; 220 | files = ( 221 | F8A148251FA281C50099271B /* NSSwitch.swift in Sources */, 222 | F8A148261FA281C80099271B /* NSSwitchThumbView.swift in Sources */, 223 | ); 224 | runOnlyForDeploymentPostprocessing = 0; 225 | }; 226 | F8FE2DB81FA2C8C7004F4E5C /* Sources */ = { 227 | isa = PBXSourcesBuildPhase; 228 | buildActionMask = 2147483647; 229 | files = ( 230 | F8FE2DC11FA2C8C7004F4E5C /* ViewController.swift in Sources */, 231 | F8FE2DBF1FA2C8C7004F4E5C /* AppDelegate.swift in Sources */, 232 | ); 233 | runOnlyForDeploymentPostprocessing = 0; 234 | }; 235 | /* End PBXSourcesBuildPhase section */ 236 | 237 | /* Begin PBXTargetDependency section */ 238 | F8FE2DCD1FA2C8DF004F4E5C /* PBXTargetDependency */ = { 239 | isa = PBXTargetDependency; 240 | target = F8A148031FA2809D0099271B /* NSSwitch */; 241 | targetProxy = F8FE2DCC1FA2C8DF004F4E5C /* PBXContainerItemProxy */; 242 | }; 243 | /* End PBXTargetDependency section */ 244 | 245 | /* Begin PBXVariantGroup section */ 246 | F8FE2DC41FA2C8C7004F4E5C /* Main.storyboard */ = { 247 | isa = PBXVariantGroup; 248 | children = ( 249 | F8FE2DC51FA2C8C7004F4E5C /* Base */, 250 | ); 251 | name = Main.storyboard; 252 | sourceTree = ""; 253 | }; 254 | /* End PBXVariantGroup section */ 255 | 256 | /* Begin XCBuildConfiguration section */ 257 | F8A148161FA2809D0099271B /* Debug */ = { 258 | isa = XCBuildConfiguration; 259 | buildSettings = { 260 | ALWAYS_SEARCH_USER_PATHS = NO; 261 | CLANG_ANALYZER_NONNULL = YES; 262 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 263 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 264 | CLANG_CXX_LIBRARY = "libc++"; 265 | CLANG_ENABLE_MODULES = YES; 266 | CLANG_ENABLE_OBJC_ARC = YES; 267 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 268 | CLANG_WARN_BOOL_CONVERSION = YES; 269 | CLANG_WARN_COMMA = YES; 270 | CLANG_WARN_CONSTANT_CONVERSION = YES; 271 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 272 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 273 | CLANG_WARN_EMPTY_BODY = YES; 274 | CLANG_WARN_ENUM_CONVERSION = YES; 275 | CLANG_WARN_INFINITE_RECURSION = YES; 276 | CLANG_WARN_INT_CONVERSION = YES; 277 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 278 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 279 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 280 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 281 | CLANG_WARN_STRICT_PROTOTYPES = YES; 282 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 283 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 284 | CLANG_WARN_UNREACHABLE_CODE = YES; 285 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 286 | CODE_SIGN_IDENTITY = "Mac Developer"; 287 | COPY_PHASE_STRIP = NO; 288 | CURRENT_PROJECT_VERSION = 1; 289 | DEBUG_INFORMATION_FORMAT = dwarf; 290 | ENABLE_STRICT_OBJC_MSGSEND = YES; 291 | ENABLE_TESTABILITY = YES; 292 | GCC_C_LANGUAGE_STANDARD = gnu11; 293 | GCC_DYNAMIC_NO_PIC = NO; 294 | GCC_NO_COMMON_BLOCKS = YES; 295 | GCC_OPTIMIZATION_LEVEL = 0; 296 | GCC_PREPROCESSOR_DEFINITIONS = ( 297 | "DEBUG=1", 298 | "$(inherited)", 299 | ); 300 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 301 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 302 | GCC_WARN_UNDECLARED_SELECTOR = YES; 303 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 304 | GCC_WARN_UNUSED_FUNCTION = YES; 305 | GCC_WARN_UNUSED_VARIABLE = YES; 306 | MACOSX_DEPLOYMENT_TARGET = 10.11; 307 | MTL_ENABLE_DEBUG_INFO = YES; 308 | ONLY_ACTIVE_ARCH = YES; 309 | SDKROOT = macosx; 310 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 311 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 312 | VERSIONING_SYSTEM = "apple-generic"; 313 | VERSION_INFO_PREFIX = ""; 314 | }; 315 | name = Debug; 316 | }; 317 | F8A148171FA2809D0099271B /* Release */ = { 318 | isa = XCBuildConfiguration; 319 | buildSettings = { 320 | ALWAYS_SEARCH_USER_PATHS = NO; 321 | CLANG_ANALYZER_NONNULL = YES; 322 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 323 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 324 | CLANG_CXX_LIBRARY = "libc++"; 325 | CLANG_ENABLE_MODULES = YES; 326 | CLANG_ENABLE_OBJC_ARC = YES; 327 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 328 | CLANG_WARN_BOOL_CONVERSION = YES; 329 | CLANG_WARN_COMMA = YES; 330 | CLANG_WARN_CONSTANT_CONVERSION = YES; 331 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 332 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 333 | CLANG_WARN_EMPTY_BODY = YES; 334 | CLANG_WARN_ENUM_CONVERSION = YES; 335 | CLANG_WARN_INFINITE_RECURSION = YES; 336 | CLANG_WARN_INT_CONVERSION = YES; 337 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 338 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 339 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 340 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 341 | CLANG_WARN_STRICT_PROTOTYPES = YES; 342 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 343 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 344 | CLANG_WARN_UNREACHABLE_CODE = YES; 345 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 346 | CODE_SIGN_IDENTITY = "Mac Developer"; 347 | COPY_PHASE_STRIP = NO; 348 | CURRENT_PROJECT_VERSION = 1; 349 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 350 | ENABLE_NS_ASSERTIONS = NO; 351 | ENABLE_STRICT_OBJC_MSGSEND = YES; 352 | GCC_C_LANGUAGE_STANDARD = gnu11; 353 | GCC_NO_COMMON_BLOCKS = YES; 354 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 355 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 356 | GCC_WARN_UNDECLARED_SELECTOR = YES; 357 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 358 | GCC_WARN_UNUSED_FUNCTION = YES; 359 | GCC_WARN_UNUSED_VARIABLE = YES; 360 | MACOSX_DEPLOYMENT_TARGET = 10.11; 361 | MTL_ENABLE_DEBUG_INFO = NO; 362 | SDKROOT = macosx; 363 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 364 | VERSIONING_SYSTEM = "apple-generic"; 365 | VERSION_INFO_PREFIX = ""; 366 | }; 367 | name = Release; 368 | }; 369 | F8A148191FA2809D0099271B /* Debug */ = { 370 | isa = XCBuildConfiguration; 371 | buildSettings = { 372 | CODE_SIGN_IDENTITY = "Mac Developer"; 373 | CODE_SIGN_STYLE = Automatic; 374 | COMBINE_HIDPI_IMAGES = YES; 375 | DEFINES_MODULE = YES; 376 | DEVELOPMENT_TEAM = ""; 377 | DYLIB_COMPATIBILITY_VERSION = 1; 378 | DYLIB_CURRENT_VERSION = 1; 379 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 380 | FRAMEWORK_VERSION = A; 381 | INFOPLIST_FILE = NSSwitch/Info.plist; 382 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 383 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; 384 | PRODUCT_BUNDLE_IDENTIFIER = com.haydenpennington.NSSwitch; 385 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; 386 | PROVISIONING_PROFILE_SPECIFIER = ""; 387 | SKIP_INSTALL = YES; 388 | SWIFT_VERSION = 4.0; 389 | }; 390 | name = Debug; 391 | }; 392 | F8A1481A1FA2809D0099271B /* Release */ = { 393 | isa = XCBuildConfiguration; 394 | buildSettings = { 395 | CODE_SIGN_IDENTITY = "Mac Developer"; 396 | CODE_SIGN_STYLE = Automatic; 397 | COMBINE_HIDPI_IMAGES = YES; 398 | DEFINES_MODULE = YES; 399 | DEVELOPMENT_TEAM = ""; 400 | DYLIB_COMPATIBILITY_VERSION = 1; 401 | DYLIB_CURRENT_VERSION = 1; 402 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 403 | FRAMEWORK_VERSION = A; 404 | INFOPLIST_FILE = NSSwitch/Info.plist; 405 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 406 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; 407 | PRODUCT_BUNDLE_IDENTIFIER = com.haydenpennington.NSSwitch; 408 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; 409 | PROVISIONING_PROFILE_SPECIFIER = ""; 410 | SKIP_INSTALL = YES; 411 | SWIFT_VERSION = 4.0; 412 | }; 413 | name = Release; 414 | }; 415 | F8FE2DC91FA2C8C7004F4E5C /* Debug */ = { 416 | isa = XCBuildConfiguration; 417 | buildSettings = { 418 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 419 | CODE_SIGN_IDENTITY = "-"; 420 | CODE_SIGN_STYLE = Automatic; 421 | COMBINE_HIDPI_IMAGES = YES; 422 | INFOPLIST_FILE = NSSwitchDemo/Info.plist; 423 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; 424 | PRODUCT_BUNDLE_IDENTIFIER = com.haydenpennington.NSSwitchDemo; 425 | PRODUCT_NAME = "$(TARGET_NAME)"; 426 | SWIFT_VERSION = 4.0; 427 | }; 428 | name = Debug; 429 | }; 430 | F8FE2DCA1FA2C8C7004F4E5C /* Release */ = { 431 | isa = XCBuildConfiguration; 432 | buildSettings = { 433 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 434 | CODE_SIGN_IDENTITY = "-"; 435 | CODE_SIGN_STYLE = Automatic; 436 | COMBINE_HIDPI_IMAGES = YES; 437 | INFOPLIST_FILE = NSSwitchDemo/Info.plist; 438 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; 439 | PRODUCT_BUNDLE_IDENTIFIER = com.haydenpennington.NSSwitchDemo; 440 | PRODUCT_NAME = "$(TARGET_NAME)"; 441 | SWIFT_VERSION = 4.0; 442 | }; 443 | name = Release; 444 | }; 445 | /* End XCBuildConfiguration section */ 446 | 447 | /* Begin XCConfigurationList section */ 448 | F8A147FE1FA2809D0099271B /* Build configuration list for PBXProject "NSSwitch" */ = { 449 | isa = XCConfigurationList; 450 | buildConfigurations = ( 451 | F8A148161FA2809D0099271B /* Debug */, 452 | F8A148171FA2809D0099271B /* Release */, 453 | ); 454 | defaultConfigurationIsVisible = 0; 455 | defaultConfigurationName = Release; 456 | }; 457 | F8A148181FA2809D0099271B /* Build configuration list for PBXNativeTarget "NSSwitch" */ = { 458 | isa = XCConfigurationList; 459 | buildConfigurations = ( 460 | F8A148191FA2809D0099271B /* Debug */, 461 | F8A1481A1FA2809D0099271B /* Release */, 462 | ); 463 | defaultConfigurationIsVisible = 0; 464 | defaultConfigurationName = Release; 465 | }; 466 | F8FE2DCB1FA2C8C7004F4E5C /* Build configuration list for PBXNativeTarget "NSSwitchDemo" */ = { 467 | isa = XCConfigurationList; 468 | buildConfigurations = ( 469 | F8FE2DC91FA2C8C7004F4E5C /* Debug */, 470 | F8FE2DCA1FA2C8C7004F4E5C /* Release */, 471 | ); 472 | defaultConfigurationIsVisible = 0; 473 | defaultConfigurationName = Release; 474 | }; 475 | /* End XCConfigurationList section */ 476 | }; 477 | rootObject = F8A147FB1FA2809D0099271B /* Project object */; 478 | } 479 | -------------------------------------------------------------------------------- /NSSwitch.xcodeproj/xcshareddata/xcschemes/NSSwitch.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 31 | 32 | 33 | 34 | 35 | 36 | 47 | 48 | 54 | 55 | 56 | 57 | 58 | 59 | 65 | 66 | 72 | 73 | 74 | 75 | 77 | 78 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /NSSwitch/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 | FMWK 17 | CFBundleShortVersionString 18 | 1.1.4 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | NSHumanReadableCopyright 22 | Copyright © 2017 Hayden Pennington. All rights reserved. 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /NSSwitch/NSSwitch.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSSwitch.h 3 | // 4 | 5 | #import 6 | 7 | //! Project version number for NSSwitch. 8 | FOUNDATION_EXPORT double NSSwitchVersionNumber; 9 | 10 | //! Project version string for NSSwitch. 11 | FOUNDATION_EXPORT const unsigned char NSSwitchVersionString[]; 12 | 13 | // In this header, you should import all the public headers of your framework using statements like #import 14 | -------------------------------------------------------------------------------- /NSSwitch/NSSwitch.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NSSwitch.swift 3 | // 4 | 5 | import Cocoa 6 | 7 | protocol NSSwitchDelegate { 8 | func switchChanged(switch: NSSwitch) 9 | } 10 | 11 | @IBDesignable 12 | /// A UISWitch clone for macOS. 13 | public class NSSwitch: NSControl { 14 | var delegate: NSSwitchDelegate? 15 | /// Reflects the current state of the `NSSwitch`. 16 | private (set) public var on = false 17 | 18 | /// Set the `on` property, optionally animate the change. 19 | /// 20 | /// - Parameter on: The state to set the switch. 21 | /// - Parameter animated: Specify whether the state change should be animated. 22 | public func setOn(on: Bool, animated: Bool) { 23 | 24 | let bgColor = on ? onColor : offColor 25 | backgroundView.layer?.backgroundColor = bgColor.cgColor 26 | 27 | if animated { 28 | animate(on: on) 29 | } 30 | 31 | self.on = on 32 | delegate?.switchChanged(switch: self) 33 | } 34 | 35 | /// The CAMediaTimingFunction for the switch animation. 36 | public var mediaTimingFunction = kCAMediaTimingFunctionEaseIn 37 | 38 | /// The duration of the switch animation. 39 | /// default value is 0.20. 40 | public var thumbAnimationDuration = 0.20 41 | 42 | /// The `NSColor` value of the `backgroundView` when the property `on` is set to true. 43 | @IBInspectable public var onColor: NSColor = NSColor(red: 40/255.0, green: 150/255.0, blue: 245/255.0, alpha: 1.0) 44 | 45 | /// The `NSColor` value of the `backgroundView` when the property `on` is set to false. 46 | @IBInspectable public var offColor: NSColor = NSColor(red: 114/255.0, green: 114/255.0, blue: 114/255.0, alpha: 1.0) { 47 | didSet { backgroundView.layer?.backgroundColor = offColor.cgColor } 48 | } 49 | 50 | /// The `NSColor` value of the `thumbView`. 51 | @IBInspectable public var thumbColor: NSColor = NSColor.white { 52 | didSet { thumbView.layer?.backgroundColor = thumbColor.cgColor } 53 | } 54 | 55 | /// The background `NSView` of the `NSSwitch`. 56 | public var backgroundView: NSView! 57 | 58 | /// An instance of `NSSwitchThumbView` for the thumb knob component. 59 | public var thumbView: NSSwitchThumbView! 60 | 61 | public required init?(coder: NSCoder) { 62 | super.init(coder: coder) 63 | setup() 64 | } 65 | 66 | public override init(frame frameRect: NSRect) { 67 | super.init(frame: frameRect) 68 | setup() 69 | } 70 | 71 | private var dragVelocityGain: CGFloat = 0.3 72 | 73 | private var radius: CGFloat { 74 | return self.bounds.size.height / 2 75 | } 76 | 77 | private func setup() { 78 | drawBGView() 79 | drawThumbKnobView() 80 | let clickRecognizer = NSClickGestureRecognizer(target: self, action: #selector(NSSwitch.clicked(click:))) 81 | let panRecognizer = NSPanGestureRecognizer(target: self, action: #selector(NSSwitch.panned(pan:))) 82 | thumbView.addGestureRecognizer(panRecognizer) 83 | backgroundView.addGestureRecognizer(clickRecognizer) 84 | backgroundView.addSubview(thumbView) 85 | self.addSubview(backgroundView) 86 | } 87 | 88 | private func drawThumbKnobView() { 89 | let thumbOrigin = CGPoint(x: backgroundView.bounds.origin.x, 90 | y: backgroundView.bounds.origin.y) 91 | 92 | let diameter = backgroundView.bounds.size.height 93 | let thumbSize = CGSize(width: diameter, height: diameter) 94 | let thumbFrame = CGRect(origin: thumbOrigin, size: thumbSize) 95 | thumbView = NSSwitchThumbView(frame: thumbFrame) 96 | thumbView.wantsLayer = true 97 | 98 | if let layer = thumbView.layer { 99 | layer.backgroundColor = thumbColor.cgColor 100 | layer.cornerRadius = radius 101 | } 102 | } 103 | 104 | private func drawBGView() { 105 | // Draw the backgroundView 106 | backgroundView = NSView(frame: self.bounds) 107 | backgroundView.wantsLayer = true 108 | 109 | if let layer = backgroundView.layer { 110 | layer.backgroundColor = offColor.cgColor 111 | layer.cornerRadius = radius 112 | } 113 | } 114 | 115 | // MARK: - NSGesture handlers. 116 | 117 | @objc private func clicked(click: NSClickGestureRecognizer) { 118 | setOn(on: !on, animated: true) 119 | sendAction(self.action, to: self.target) 120 | } 121 | 122 | @objc private func panned(pan: NSPanGestureRecognizer) { 123 | switch pan.state { 124 | case .changed: 125 | changed(pan: pan) 126 | break 127 | case .ended: 128 | sendAction(self.action, to: self.target) 129 | moveToNearestSwitchPosition() 130 | break 131 | default: 132 | break 133 | } 134 | } 135 | 136 | private func changed(pan: NSPanGestureRecognizer) { 137 | updatePosition(pan: pan) 138 | let x = thumbView.frame.origin.x 139 | let thumbViewWidth = thumbView.bounds.size.width 140 | let backgroundViewWidth = backgroundView.bounds.size.width 141 | if x + thumbViewWidth / 2 >= backgroundViewWidth / 2 { 142 | setOn(on: true, animated: false) 143 | } else { 144 | setOn(on: false, animated: false) 145 | } 146 | } 147 | 148 | private func animate(on: Bool) { 149 | CATransaction.begin() 150 | CATransaction.setAnimationDuration(thumbAnimationDuration) 151 | CATransaction.setAnimationTimingFunction(CAMediaTimingFunction(name: mediaTimingFunction)) 152 | 153 | if on { 154 | let x = backgroundView.bounds.size.width - thumbView.frame.size.width 155 | let destinationOrigin = CGPoint(x: x, y: 0) 156 | thumbView.animator().setFrameOrigin(destinationOrigin) 157 | } 158 | else { 159 | let destinationOrigin = CGPoint(x: 0, y: 0) 160 | thumbView.animator().setFrameOrigin(destinationOrigin) 161 | } 162 | 163 | CATransaction.commit() 164 | } 165 | 166 | private func updatePosition(pan: NSPanGestureRecognizer) { 167 | let thumbWidth = thumbView.bounds.size.width 168 | let leadingSpace = thumbView.frame.origin.x 169 | let trailingSpace = backgroundView.bounds.size.width - (leadingSpace + thumbWidth) 170 | let xTranslation = pan.translation(in: backgroundView).x 171 | 172 | if xTranslation >= 0 { 173 | let delta = trailingSpace >= xTranslation ? xTranslation : trailingSpace 174 | thumbView.frame.origin.x += delta * dragVelocityGain 175 | } else { 176 | if leadingSpace >= -xTranslation { 177 | thumbView.frame.origin.x += xTranslation * dragVelocityGain 178 | } else { 179 | thumbView.frame.origin.x += -leadingSpace * dragVelocityGain 180 | } 181 | } 182 | } 183 | 184 | private func moveToNearestSwitchPosition() { 185 | setOn(on: on, animated: true) 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /NSSwitch/NSSwitchThumbView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NSSwitchThumbView.swift 3 | // 4 | 5 | import Cocoa 6 | 7 | /// The 'thumb' component of an `NSSwitch`. 8 | public class NSSwitchThumbView: NSView { 9 | 10 | /// Specifies the width of the detail line drawn along the edge of the `MOThumbView`. 11 | public var lineWidth: CGFloat = 0.125 12 | // Specifies the color of the detail line drawn along the edge of the `MOThumbView`. 13 | public var lineColor = NSColor.black 14 | 15 | public override func draw(_ dirtyRect: NSRect) { 16 | super.draw(dirtyRect) 17 | let center = NSPoint(x: bounds.size.height / 2, y: bounds.size.height / 2) 18 | let path = NSBezierPath() 19 | let rad = bounds.size.height / 2 - 0.5 20 | let startAngle: CGFloat = 0 21 | let endAngle: CGFloat = 360 22 | 23 | path.appendArc(withCenter: center, radius: rad, startAngle: startAngle, endAngle: endAngle) 24 | lineColor.setStroke() 25 | path.lineWidth = lineWidth 26 | path.stroke() 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /NSSwitchDemo/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // 4 | 5 | import Cocoa 6 | 7 | @NSApplicationMain 8 | class AppDelegate: NSObject, NSApplicationDelegate {} 9 | -------------------------------------------------------------------------------- /NSSwitchDemo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "mac", 5 | "size" : "16x16", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "mac", 10 | "size" : "16x16", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "mac", 15 | "size" : "32x32", 16 | "scale" : "1x" 17 | }, 18 | { 19 | "idiom" : "mac", 20 | "size" : "32x32", 21 | "scale" : "2x" 22 | }, 23 | { 24 | "idiom" : "mac", 25 | "size" : "128x128", 26 | "scale" : "1x" 27 | }, 28 | { 29 | "idiom" : "mac", 30 | "size" : "128x128", 31 | "scale" : "2x" 32 | }, 33 | { 34 | "idiom" : "mac", 35 | "size" : "256x256", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "mac", 40 | "size" : "256x256", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "mac", 45 | "size" : "512x512", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "mac", 50 | "size" : "512x512", 51 | "scale" : "2x" 52 | } 53 | ], 54 | "info" : { 55 | "version" : 1, 56 | "author" : "xcode" 57 | } 58 | } -------------------------------------------------------------------------------- /NSSwitchDemo/Base.lproj/Main.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 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | Default 531 | 532 | 533 | 534 | 535 | 536 | 537 | Left to Right 538 | 539 | 540 | 541 | 542 | 543 | 544 | Right to Left 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | Default 556 | 557 | 558 | 559 | 560 | 561 | 562 | Left to Right 563 | 564 | 565 | 566 | 567 | 568 | 569 | Right to Left 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 744 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 | 753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 798 | 799 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 | 833 | 834 | 835 | 836 | 837 | 838 | 839 | 840 | 841 | 842 | 843 | 844 | 845 | 846 | 847 | 848 | 849 | 850 | 851 | 852 | 853 | 854 | 855 | 856 | 857 | 858 | 859 | 860 | 861 | 862 | 863 | 864 | 865 | 866 | 867 | 868 | 869 | 870 | 871 | 872 | 873 | 874 | 875 | 876 | 877 | 878 | 879 | 880 | 881 | 882 | 883 | 884 | 885 | 886 | 887 | 888 | 889 | 890 | 891 | 892 | 893 | 894 | 895 | 896 | 897 | 898 | 899 | 900 | 901 | 902 | 903 | 904 | 905 | 906 | 907 | 908 | -------------------------------------------------------------------------------- /NSSwitchDemo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleVersion 22 | 1 23 | LSMinimumSystemVersion 24 | $(MACOSX_DEPLOYMENT_TARGET) 25 | NSHumanReadableCopyright 26 | Copyright © 2017 Hayden Pennington. All rights reserved. 27 | NSMainStoryboardFile 28 | Main 29 | NSPrincipalClass 30 | NSApplication 31 | 32 | 33 | -------------------------------------------------------------------------------- /NSSwitchDemo/NSSwitchDemo.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /NSSwitchDemo/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // 4 | 5 | import Cocoa 6 | import MapKit 7 | import NSSwitch 8 | import CoreLocation 9 | 10 | class ViewController: NSViewController { 11 | @IBOutlet weak var mapView: MKMapView! 12 | 13 | @IBAction func toggleSwitch(_ sender: NSSwitch) { 14 | if let id = sender.identifier { 15 | let newState = sender.on 16 | if (id.rawValue == "traffic") { 17 | mapView.showsTraffic = newState 18 | } else if (id.rawValue == "buildings") { 19 | mapView.showsBuildings = newState 20 | } else if (id.rawValue == "compass") { 21 | mapView.showsCompass = newState 22 | } else if (id.rawValue == "pointsOfInterest") { 23 | mapView.showsPointsOfInterest = newState 24 | } 25 | } 26 | } 27 | 28 | @IBAction func searchFieldChanged(_ sender: NSSearchField) { 29 | let query = sender.stringValue 30 | search(naturalLanguageQuery: query) 31 | } 32 | 33 | func search(naturalLanguageQuery: String) { 34 | let request = MKLocalSearchRequest() 35 | request.naturalLanguageQuery = naturalLanguageQuery 36 | request.region = mapView.region 37 | let search = MKLocalSearch(request: request) 38 | 39 | search.start { (response, error) in 40 | if let mapItems = response?.mapItems { 41 | self.updateDisplay(mapItems: mapItems) 42 | } 43 | } 44 | } 45 | 46 | func updateDisplay(mapItems: [MKMapItem]) { 47 | if let coord = mapItems.first?.placemark.coordinate { 48 | let latDelta = 0.1 49 | let lonDelta = 0.1 50 | self.updateRegion(center: coord, latDelta: latDelta, lonDelta: lonDelta) 51 | } 52 | } 53 | 54 | func updateRegion(center: CLLocationCoordinate2D, latDelta: CLLocationDegrees, lonDelta: CLLocationDegrees) { 55 | let span = MKCoordinateSpan(latitudeDelta: latDelta, longitudeDelta: lonDelta) 56 | let region = MKCoordinateRegion(center: center, span: span) 57 | mapView.setRegion(region, animated: true) 58 | } 59 | 60 | @IBAction func segmentedControlChanged(_ sender: NSSegmentedControl) { 61 | let index = sender.selectedSegment 62 | if (index == 0) { 63 | mapView.mapType = .standard 64 | } else { 65 | mapView.mapType = .hybrid 66 | } 67 | } 68 | 69 | override func viewDidLoad() { 70 | super.viewDidLoad() 71 | mapView.showsPointsOfInterest = false 72 | mapView.showsCompass = false 73 | mapView.showsBuildings = false 74 | mapView.showsTraffic = false 75 | 76 | search(naturalLanguageQuery: "36.165847, -86.809796") 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /NSSwitch_screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpennington/NSSwitch/233dd615194cfdb8aaae501fe9f865a555bb7e9f/NSSwitch_screenshot.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NSSwitch 2 | 3 | UISwitch for macOS. 4 | 5 | [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) 6 | [![Version](https://img.shields.io/cocoapods/v/NSSwitch.svg?style=flat)](http://cocoapods.org/pods/NSSwitch) 7 | 8 | ## Demo app 9 | ![](./NSSwitch_screenshot.png) 10 | 11 | 12 | ## Installation 13 | 14 | #### Carthage 15 | 16 | - Add NSSwitch dependency to the Cartfile: 17 | ``` 18 | github "https://github.com/hpennington/NSSwitch.git" 19 | ``` 20 | 21 | #### CocoaPods 22 | 23 | NSSwitch is alxo available through [CocoaPods](http://cocoapods.org). To install 24 | NSSwitch with CocoaPods, simply add the following line to your Podfile: 25 | 26 | ``` 27 | pod "NSSwitch" 28 | ``` 29 | 30 | ## Author 31 | 32 | Hayden Pennington, haydenpennington@icloud.com 33 | 34 | ## License 35 | 36 | NSSwitch is available under the MIT license. See the LICENSE file for more info. 37 | 38 | --------------------------------------------------------------------------------