├── .editorconfig ├── .gitignore ├── .swift-version ├── .travis.yml ├── Example ├── Example.xcodeproj │ ├── project.pbxproj │ └── xcshareddata │ │ └── xcschemes │ │ └── Example.xcscheme └── Example │ ├── AppDelegate.swift │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ └── ViewController.swift ├── HueKit.podspec ├── HueKit.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcshareddata │ └── xcschemes │ └── HueKit.xcscheme ├── HueKit.xcworkspace ├── contents.xcworkspacedata └── xcshareddata │ └── IDEWorkspaceChecks.plist ├── HueKit ├── HueKit.h ├── Info.plist ├── Model │ ├── HSBComponent.swift │ ├── HSV.swift │ └── RGB.swift ├── Util │ ├── CGFloat+Pin.swift │ ├── HSBGen.swift │ └── UIColor+Values.swift └── View │ ├── ColorBarPicker.swift │ ├── ColorBarView.swift │ ├── ColorIndicatorView.swift │ ├── ColorSquarePicker.swift │ ├── ColorSquareView.swift │ └── SourceColorView.swift ├── LICENSE ├── README.md └── readme-resources ├── components ├── ColorBarPicker.png ├── ColorBarView.png ├── ColorIndicatorView.png ├── ColorSquarePicker.png ├── ColorSquareView.png └── SourceColorView.png ├── example.gif └── hero@2x.png /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | indent_size = 4 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | .DS_Store 4 | build/ 5 | *.pbxuser 6 | !default.pbxuser 7 | *.mode1v3 8 | !default.mode1v3 9 | *.mode2v3 10 | !default.mode2v3 11 | *.perspectivev3 12 | !default.perspectivev3 13 | xcuserdata 14 | *.xccheckout 15 | *.moved-aside 16 | DerivedData 17 | *.hmap 18 | *.ipa 19 | *.xcuserstate 20 | 21 | -------------------------------------------------------------------------------- /.swift-version: -------------------------------------------------------------------------------- 1 | 4.1 -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: objective-c 2 | osx_image: xcode9.3 3 | branches: 4 | only: 5 | - master 6 | env: 7 | global: 8 | - LC_CTYPE=en_US.UTF-8 9 | - LANG=en_US.UTF-8 10 | - WORKSPACE=HueKit.xcworkspace 11 | - IOS_FRAMEWORK_SCHEME="HueKit" 12 | - EXAMPLE_SCHEME="Example" 13 | matrix: 14 | 15 | - DESTINATION="OS=10.0,name=iPhone 7" SCHEME="$IOS_FRAMEWORK_SCHEME" RUN_TESTS="NO" BUILD_EXAMPLE="YES" CODE_COV="NO" 16 | - DESTINATION="OS=11.3,name=iPad Pro (9.7-inch)" SCHEME="$IOS_FRAMEWORK_SCHEME" RUN_TESTS="NO" BUILD_EXAMPLE="YES" CODE_COV="NO" 17 | 18 | script: 19 | - set -o pipefail 20 | - xcodebuild -version 21 | - xcodebuild -showsdks 22 | 23 | # Build Framework in Debug and Run Tests if specified 24 | - if [ $RUN_TESTS == "YES" ]; then 25 | travis_retry xcodebuild -workspace "$WORKSPACE" -scheme "$SCHEME" -destination "$DESTINATION" -configuration Debug ONLY_ACTIVE_ARCH=NO ENABLE_TESTABILITY=YES test | xcpretty; 26 | else 27 | travis_retry xcodebuild -workspace "$WORKSPACE" -scheme "$SCHEME" -destination "$DESTINATION" -configuration Debug ONLY_ACTIVE_ARCH=NO build | xcpretty; 28 | fi 29 | 30 | # Build Framework in Release and Run Tests if specified 31 | - if [ $RUN_TESTS == "YES" ]; then 32 | travis_retry xcodebuild -workspace "$WORKSPACE" -scheme "$SCHEME" -destination "$DESTINATION" -configuration Release ONLY_ACTIVE_ARCH=NO ENABLE_TESTABILITY=YES test | xcpretty; 33 | else 34 | travis_retry xcodebuild -workspace "$WORKSPACE" -scheme "$SCHEME" -destination "$DESTINATION" -configuration Release ONLY_ACTIVE_ARCH=NO build | xcpretty; 35 | fi 36 | 37 | # Build Example in Debug if specified 38 | - if [ $BUILD_EXAMPLE == "YES" ]; then 39 | travis_retry xcodebuild -workspace "$WORKSPACE" -scheme "$EXAMPLE_SCHEME" -destination "$DESTINATION" -configuration Debug ONLY_ACTIVE_ARCH=NO build | xcpretty; 40 | fi 41 | 42 | # Build and report code coverage if specified 43 | - if [ $CODE_COV == "YES" ]; then 44 | xcodebuild -workspace "$WORKSPACE" -scheme "$SCHEME" -destination "$DESTINATION" -configuration Release ONLY_ACTIVE_ARCH=YES ENABLE_TESTABILITY=YES -enableCodeCoverage YES test; 45 | fi 46 | 47 | after_success: 48 | - bash <(curl -s https://codecov.io/bash) 49 | 50 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | BEB7754C207267E400201EBB /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEB7754B207267E400201EBB /* AppDelegate.swift */; }; 11 | BEB7754E207267E400201EBB /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEB7754D207267E400201EBB /* ViewController.swift */; }; 12 | BEB77551207267E400201EBB /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BEB7754F207267E400201EBB /* Main.storyboard */; }; 13 | BEB77553207267E500201EBB /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BEB77552207267E500201EBB /* Assets.xcassets */; }; 14 | BEB77556207267E500201EBB /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BEB77554207267E500201EBB /* LaunchScreen.storyboard */; }; 15 | BEB7755E207267F800201EBB /* HueKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BEB7755D207267F800201EBB /* HueKit.framework */; }; 16 | BEB7755F207267F800201EBB /* HueKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = BEB7755D207267F800201EBB /* HueKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXCopyFilesBuildPhase section */ 20 | BEB77560207267F800201EBB /* Embed Frameworks */ = { 21 | isa = PBXCopyFilesBuildPhase; 22 | buildActionMask = 2147483647; 23 | dstPath = ""; 24 | dstSubfolderSpec = 10; 25 | files = ( 26 | BEB7755F207267F800201EBB /* HueKit.framework in Embed Frameworks */, 27 | ); 28 | name = "Embed Frameworks"; 29 | runOnlyForDeploymentPostprocessing = 0; 30 | }; 31 | /* End PBXCopyFilesBuildPhase section */ 32 | 33 | /* Begin PBXFileReference section */ 34 | BEB77548207267E400201EBB /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; 35 | BEB7754B207267E400201EBB /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 36 | BEB7754D207267E400201EBB /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 37 | BEB77550207267E400201EBB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 38 | BEB77552207267E500201EBB /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 39 | BEB77555207267E500201EBB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 40 | BEB77557207267E500201EBB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 41 | BEB7755D207267F800201EBB /* HueKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = HueKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 42 | /* End PBXFileReference section */ 43 | 44 | /* Begin PBXFrameworksBuildPhase section */ 45 | BEB77545207267E400201EBB /* Frameworks */ = { 46 | isa = PBXFrameworksBuildPhase; 47 | buildActionMask = 2147483647; 48 | files = ( 49 | BEB7755E207267F800201EBB /* HueKit.framework in Frameworks */, 50 | ); 51 | runOnlyForDeploymentPostprocessing = 0; 52 | }; 53 | /* End PBXFrameworksBuildPhase section */ 54 | 55 | /* Begin PBXGroup section */ 56 | BEB7753F207267E400201EBB = { 57 | isa = PBXGroup; 58 | children = ( 59 | BEB7755D207267F800201EBB /* HueKit.framework */, 60 | BEB7754A207267E400201EBB /* Example */, 61 | BEB77549207267E400201EBB /* Products */, 62 | ); 63 | sourceTree = ""; 64 | }; 65 | BEB77549207267E400201EBB /* Products */ = { 66 | isa = PBXGroup; 67 | children = ( 68 | BEB77548207267E400201EBB /* Example.app */, 69 | ); 70 | name = Products; 71 | sourceTree = ""; 72 | }; 73 | BEB7754A207267E400201EBB /* Example */ = { 74 | isa = PBXGroup; 75 | children = ( 76 | BEB7754B207267E400201EBB /* AppDelegate.swift */, 77 | BEB7754D207267E400201EBB /* ViewController.swift */, 78 | BEB7754F207267E400201EBB /* Main.storyboard */, 79 | BEB77552207267E500201EBB /* Assets.xcassets */, 80 | BEB77554207267E500201EBB /* LaunchScreen.storyboard */, 81 | BEB77557207267E500201EBB /* Info.plist */, 82 | ); 83 | path = Example; 84 | sourceTree = ""; 85 | }; 86 | /* End PBXGroup section */ 87 | 88 | /* Begin PBXNativeTarget section */ 89 | BEB77547207267E400201EBB /* Example */ = { 90 | isa = PBXNativeTarget; 91 | buildConfigurationList = BEB7755A207267E500201EBB /* Build configuration list for PBXNativeTarget "Example" */; 92 | buildPhases = ( 93 | BEB77544207267E400201EBB /* Sources */, 94 | BEB77545207267E400201EBB /* Frameworks */, 95 | BEB77546207267E400201EBB /* Resources */, 96 | BEB77560207267F800201EBB /* Embed Frameworks */, 97 | ); 98 | buildRules = ( 99 | ); 100 | dependencies = ( 101 | ); 102 | name = Example; 103 | productName = Example; 104 | productReference = BEB77548207267E400201EBB /* Example.app */; 105 | productType = "com.apple.product-type.application"; 106 | }; 107 | /* End PBXNativeTarget section */ 108 | 109 | /* Begin PBXProject section */ 110 | BEB77540207267E400201EBB /* Project object */ = { 111 | isa = PBXProject; 112 | attributes = { 113 | LastSwiftUpdateCheck = 0930; 114 | LastUpgradeCheck = 0930; 115 | ORGANIZATIONNAME = "Silver Fox"; 116 | TargetAttributes = { 117 | BEB77547207267E400201EBB = { 118 | CreatedOnToolsVersion = 9.3; 119 | }; 120 | }; 121 | }; 122 | buildConfigurationList = BEB77543207267E400201EBB /* Build configuration list for PBXProject "Example" */; 123 | compatibilityVersion = "Xcode 9.3"; 124 | developmentRegion = en; 125 | hasScannedForEncodings = 0; 126 | knownRegions = ( 127 | en, 128 | Base, 129 | ); 130 | mainGroup = BEB7753F207267E400201EBB; 131 | productRefGroup = BEB77549207267E400201EBB /* Products */; 132 | projectDirPath = ""; 133 | projectRoot = ""; 134 | targets = ( 135 | BEB77547207267E400201EBB /* Example */, 136 | ); 137 | }; 138 | /* End PBXProject section */ 139 | 140 | /* Begin PBXResourcesBuildPhase section */ 141 | BEB77546207267E400201EBB /* Resources */ = { 142 | isa = PBXResourcesBuildPhase; 143 | buildActionMask = 2147483647; 144 | files = ( 145 | BEB77556207267E500201EBB /* LaunchScreen.storyboard in Resources */, 146 | BEB77553207267E500201EBB /* Assets.xcassets in Resources */, 147 | BEB77551207267E400201EBB /* Main.storyboard in Resources */, 148 | ); 149 | runOnlyForDeploymentPostprocessing = 0; 150 | }; 151 | /* End PBXResourcesBuildPhase section */ 152 | 153 | /* Begin PBXSourcesBuildPhase section */ 154 | BEB77544207267E400201EBB /* Sources */ = { 155 | isa = PBXSourcesBuildPhase; 156 | buildActionMask = 2147483647; 157 | files = ( 158 | BEB7754E207267E400201EBB /* ViewController.swift in Sources */, 159 | BEB7754C207267E400201EBB /* AppDelegate.swift in Sources */, 160 | ); 161 | runOnlyForDeploymentPostprocessing = 0; 162 | }; 163 | /* End PBXSourcesBuildPhase section */ 164 | 165 | /* Begin PBXVariantGroup section */ 166 | BEB7754F207267E400201EBB /* Main.storyboard */ = { 167 | isa = PBXVariantGroup; 168 | children = ( 169 | BEB77550207267E400201EBB /* Base */, 170 | ); 171 | name = Main.storyboard; 172 | sourceTree = ""; 173 | }; 174 | BEB77554207267E500201EBB /* LaunchScreen.storyboard */ = { 175 | isa = PBXVariantGroup; 176 | children = ( 177 | BEB77555207267E500201EBB /* Base */, 178 | ); 179 | name = LaunchScreen.storyboard; 180 | sourceTree = ""; 181 | }; 182 | /* End PBXVariantGroup section */ 183 | 184 | /* Begin XCBuildConfiguration section */ 185 | BEB77558207267E500201EBB /* Debug */ = { 186 | isa = XCBuildConfiguration; 187 | buildSettings = { 188 | ALWAYS_SEARCH_USER_PATHS = NO; 189 | CLANG_ANALYZER_NONNULL = YES; 190 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 191 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 192 | CLANG_CXX_LIBRARY = "libc++"; 193 | CLANG_ENABLE_MODULES = YES; 194 | CLANG_ENABLE_OBJC_ARC = YES; 195 | CLANG_ENABLE_OBJC_WEAK = YES; 196 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 197 | CLANG_WARN_BOOL_CONVERSION = YES; 198 | CLANG_WARN_COMMA = YES; 199 | CLANG_WARN_CONSTANT_CONVERSION = YES; 200 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 201 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 202 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 203 | CLANG_WARN_EMPTY_BODY = YES; 204 | CLANG_WARN_ENUM_CONVERSION = YES; 205 | CLANG_WARN_INFINITE_RECURSION = YES; 206 | CLANG_WARN_INT_CONVERSION = YES; 207 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 208 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 209 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 210 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 211 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 212 | CLANG_WARN_STRICT_PROTOTYPES = YES; 213 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 214 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 215 | CLANG_WARN_UNREACHABLE_CODE = YES; 216 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 217 | CODE_SIGN_IDENTITY = "iPhone Developer"; 218 | COPY_PHASE_STRIP = NO; 219 | DEBUG_INFORMATION_FORMAT = dwarf; 220 | ENABLE_STRICT_OBJC_MSGSEND = YES; 221 | ENABLE_TESTABILITY = YES; 222 | GCC_C_LANGUAGE_STANDARD = gnu11; 223 | GCC_DYNAMIC_NO_PIC = NO; 224 | GCC_NO_COMMON_BLOCKS = YES; 225 | GCC_OPTIMIZATION_LEVEL = 0; 226 | GCC_PREPROCESSOR_DEFINITIONS = ( 227 | "DEBUG=1", 228 | "$(inherited)", 229 | ); 230 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 231 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 232 | GCC_WARN_UNDECLARED_SELECTOR = YES; 233 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 234 | GCC_WARN_UNUSED_FUNCTION = YES; 235 | GCC_WARN_UNUSED_VARIABLE = YES; 236 | IPHONEOS_DEPLOYMENT_TARGET = 11.3; 237 | MTL_ENABLE_DEBUG_INFO = YES; 238 | ONLY_ACTIVE_ARCH = YES; 239 | SDKROOT = iphoneos; 240 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 241 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 242 | }; 243 | name = Debug; 244 | }; 245 | BEB77559207267E500201EBB /* Release */ = { 246 | isa = XCBuildConfiguration; 247 | buildSettings = { 248 | ALWAYS_SEARCH_USER_PATHS = NO; 249 | CLANG_ANALYZER_NONNULL = YES; 250 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 251 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 252 | CLANG_CXX_LIBRARY = "libc++"; 253 | CLANG_ENABLE_MODULES = YES; 254 | CLANG_ENABLE_OBJC_ARC = YES; 255 | CLANG_ENABLE_OBJC_WEAK = YES; 256 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 257 | CLANG_WARN_BOOL_CONVERSION = YES; 258 | CLANG_WARN_COMMA = YES; 259 | CLANG_WARN_CONSTANT_CONVERSION = YES; 260 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 261 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 262 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 263 | CLANG_WARN_EMPTY_BODY = YES; 264 | CLANG_WARN_ENUM_CONVERSION = YES; 265 | CLANG_WARN_INFINITE_RECURSION = YES; 266 | CLANG_WARN_INT_CONVERSION = YES; 267 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 268 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 269 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 270 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 271 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 272 | CLANG_WARN_STRICT_PROTOTYPES = YES; 273 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 274 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 275 | CLANG_WARN_UNREACHABLE_CODE = YES; 276 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 277 | CODE_SIGN_IDENTITY = "iPhone Developer"; 278 | COPY_PHASE_STRIP = NO; 279 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 280 | ENABLE_NS_ASSERTIONS = NO; 281 | ENABLE_STRICT_OBJC_MSGSEND = YES; 282 | GCC_C_LANGUAGE_STANDARD = gnu11; 283 | GCC_NO_COMMON_BLOCKS = YES; 284 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 285 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 286 | GCC_WARN_UNDECLARED_SELECTOR = YES; 287 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 288 | GCC_WARN_UNUSED_FUNCTION = YES; 289 | GCC_WARN_UNUSED_VARIABLE = YES; 290 | IPHONEOS_DEPLOYMENT_TARGET = 11.3; 291 | MTL_ENABLE_DEBUG_INFO = NO; 292 | SDKROOT = iphoneos; 293 | SWIFT_COMPILATION_MODE = wholemodule; 294 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 295 | VALIDATE_PRODUCT = YES; 296 | }; 297 | name = Release; 298 | }; 299 | BEB7755B207267E500201EBB /* Debug */ = { 300 | isa = XCBuildConfiguration; 301 | buildSettings = { 302 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 303 | CODE_SIGN_STYLE = Automatic; 304 | DEVELOPMENT_TEAM = 6G5LMQ72D8; 305 | INFOPLIST_FILE = Example/Info.plist; 306 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 307 | LD_RUNPATH_SEARCH_PATHS = ( 308 | "$(inherited)", 309 | "@executable_path/Frameworks", 310 | ); 311 | PRODUCT_BUNDLE_IDENTIFIER = be.silverfox.Example; 312 | PRODUCT_NAME = "$(TARGET_NAME)"; 313 | SWIFT_VERSION = 4.0; 314 | TARGETED_DEVICE_FAMILY = "1,2"; 315 | }; 316 | name = Debug; 317 | }; 318 | BEB7755C207267E500201EBB /* Release */ = { 319 | isa = XCBuildConfiguration; 320 | buildSettings = { 321 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 322 | CODE_SIGN_STYLE = Automatic; 323 | DEVELOPMENT_TEAM = 6G5LMQ72D8; 324 | INFOPLIST_FILE = Example/Info.plist; 325 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 326 | LD_RUNPATH_SEARCH_PATHS = ( 327 | "$(inherited)", 328 | "@executable_path/Frameworks", 329 | ); 330 | PRODUCT_BUNDLE_IDENTIFIER = be.silverfox.Example; 331 | PRODUCT_NAME = "$(TARGET_NAME)"; 332 | SWIFT_VERSION = 4.0; 333 | TARGETED_DEVICE_FAMILY = "1,2"; 334 | }; 335 | name = Release; 336 | }; 337 | /* End XCBuildConfiguration section */ 338 | 339 | /* Begin XCConfigurationList section */ 340 | BEB77543207267E400201EBB /* Build configuration list for PBXProject "Example" */ = { 341 | isa = XCConfigurationList; 342 | buildConfigurations = ( 343 | BEB77558207267E500201EBB /* Debug */, 344 | BEB77559207267E500201EBB /* Release */, 345 | ); 346 | defaultConfigurationIsVisible = 0; 347 | defaultConfigurationName = Release; 348 | }; 349 | BEB7755A207267E500201EBB /* Build configuration list for PBXNativeTarget "Example" */ = { 350 | isa = XCConfigurationList; 351 | buildConfigurations = ( 352 | BEB7755B207267E500201EBB /* Debug */, 353 | BEB7755C207267E500201EBB /* Release */, 354 | ); 355 | defaultConfigurationIsVisible = 0; 356 | defaultConfigurationName = Release; 357 | }; 358 | /* End XCConfigurationList section */ 359 | }; 360 | rootObject = BEB77540207267E400201EBB /* Project object */; 361 | } 362 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /Example/Example/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Example 4 | // 5 | // Created by Louis D'hauwe on 02/04/2018. 6 | // Copyright © 2018 Silver Fox. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Example/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 | } -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Example/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 | -------------------------------------------------------------------------------- /Example/Example/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 | 68 | 74 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 98 | 104 | 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 | 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 | -------------------------------------------------------------------------------- /Example/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 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /Example/Example/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // Example 4 | // 5 | // Created by Louis D'hauwe on 02/04/2018. 6 | // Copyright © 2018 Silver Fox. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import HueKit 11 | 12 | class ViewController: UIViewController { 13 | 14 | @IBOutlet weak var colorSquarePicker: ColorSquarePicker! 15 | @IBOutlet weak var colorIndicatorView: ColorIndicatorView! 16 | 17 | @IBOutlet weak var rLabel: UILabel! 18 | @IBOutlet weak var gLabel: UILabel! 19 | @IBOutlet weak var bLabel: UILabel! 20 | 21 | @IBOutlet weak var hLabel: UILabel! 22 | @IBOutlet weak var sLabel: UILabel! 23 | @IBOutlet weak var vLabel: UILabel! 24 | 25 | @IBOutlet weak var hexLabel: UILabel! 26 | 27 | override func viewDidLoad() { 28 | super.viewDidLoad() 29 | 30 | didChangeColor(colorSquarePicker.color) 31 | 32 | } 33 | 34 | @IBAction func colorBarPickerValueChanged(_ sender: ColorBarPicker) { 35 | 36 | colorSquarePicker.hue = sender.hue 37 | didChangeColor(colorSquarePicker.color) 38 | 39 | } 40 | 41 | @IBAction func colorSquarePickerValueChanged(_ sender: ColorSquarePicker) { 42 | 43 | didChangeColor(sender.color) 44 | 45 | } 46 | 47 | func didChangeColor(_ color: UIColor) { 48 | 49 | guard let rgbValue = color.rgbValue else { 50 | return 51 | } 52 | 53 | guard let hsvValue = color.hsvValue else { 54 | return 55 | } 56 | 57 | rLabel.text = String(format: "R: %.f", rgbValue.r * 255) 58 | gLabel.text = String(format: "G: %.f", rgbValue.g * 255) 59 | bLabel.text = String(format: "B: %.f", rgbValue.b * 255) 60 | 61 | hLabel.text = String(format: "H: %.f°", hsvValue.h * 360) 62 | sLabel.text = String(format: "S: %.f%%", hsvValue.s * 100) 63 | vLabel.text = String(format: "V: %.f%%", hsvValue.v * 100) 64 | 65 | hexLabel.text = color.hexString 66 | colorIndicatorView.color = color 67 | 68 | } 69 | 70 | } 71 | 72 | extension UIColor { 73 | 74 | public var hexString: String { 75 | var r: CGFloat = 0 76 | var g: CGFloat = 0 77 | var b: CGFloat = 0 78 | var a: CGFloat = 0 79 | self.getRed(&r, green: &g, blue: &b, alpha: &a) 80 | 81 | return String(format: "#%02X%02X%02X", Int(r * 255), Int(g * 255), Int(b * 255)) 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /HueKit.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'HueKit' 3 | s.version = '1.0.1' 4 | s.license = 'MIT' 5 | s.summary = 'A UI framework for iOS that provides components and utilities for building color pickers.' 6 | s.homepage = 'https://github.com/louisdh/huekit' 7 | s.social_media_url = 'http://twitter.com/LouisDhauwe' 8 | s.authors = { 'Louis D\'hauwe' => 'louisdhauwe@silverfox.be' } 9 | s.source = { :git => 'https://github.com/louisdh/huekit.git', :tag => s.version } 10 | 11 | s.ios.deployment_target = '10.0' 12 | 13 | s.source_files = 'HueKit/**/*.swift' 14 | end 15 | -------------------------------------------------------------------------------- /HueKit.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | BE5C1E1C1F3266B600B0080C /* HueKit.h in Headers */ = {isa = PBXBuildFile; fileRef = BE5C1E1A1F3266B600B0080C /* HueKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; 11 | BE5C1E361F326E2500B0080C /* RGB.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE5C1E351F326E2500B0080C /* RGB.swift */; }; 12 | BE5C1E381F326E3300B0080C /* HSV.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE5C1E371F326E3300B0080C /* HSV.swift */; }; 13 | BE5C1E3B1F326EE600B0080C /* UIColor+Values.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE5C1E3A1F326EE600B0080C /* UIColor+Values.swift */; }; 14 | BE5C1E3D1F3270CE00B0080C /* CGFloat+Pin.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE5C1E3C1F3270CE00B0080C /* CGFloat+Pin.swift */; }; 15 | BE5C1E3F1F32710B00B0080C /* HSBComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE5C1E3E1F32710B00B0080C /* HSBComponent.swift */; }; 16 | BE5C1E471F3271D600B0080C /* ColorBarPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE5C1E401F3271D600B0080C /* ColorBarPicker.swift */; }; 17 | BE5C1E481F3271D600B0080C /* ColorBarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE5C1E411F3271D600B0080C /* ColorBarView.swift */; }; 18 | BE5C1E491F3271D600B0080C /* ColorIndicatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE5C1E421F3271D600B0080C /* ColorIndicatorView.swift */; }; 19 | BE5C1E4A1F3271D600B0080C /* ColorSquarePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE5C1E431F3271D600B0080C /* ColorSquarePicker.swift */; }; 20 | BE5C1E4B1F3271D600B0080C /* ColorSquareView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE5C1E441F3271D600B0080C /* ColorSquareView.swift */; }; 21 | BE5C1E4D1F3271D600B0080C /* SourceColorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE5C1E461F3271D600B0080C /* SourceColorView.swift */; }; 22 | BE5C1E4F1F3271E900B0080C /* HSBGen.swift in Sources */ = {isa = PBXBuildFile; fileRef = BE5C1E4E1F3271E900B0080C /* HSBGen.swift */; }; 23 | /* End PBXBuildFile section */ 24 | 25 | /* Begin PBXFileReference section */ 26 | BE5C1E171F3266B600B0080C /* HueKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = HueKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 27 | BE5C1E1A1F3266B600B0080C /* HueKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = HueKit.h; sourceTree = ""; }; 28 | BE5C1E1B1F3266B600B0080C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 29 | BE5C1E351F326E2500B0080C /* RGB.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = RGB.swift; path = Model/RGB.swift; sourceTree = ""; }; 30 | BE5C1E371F326E3300B0080C /* HSV.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = HSV.swift; path = Model/HSV.swift; sourceTree = ""; }; 31 | BE5C1E3A1F326EE600B0080C /* UIColor+Values.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "UIColor+Values.swift"; path = "Util/UIColor+Values.swift"; sourceTree = ""; }; 32 | BE5C1E3C1F3270CE00B0080C /* CGFloat+Pin.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "CGFloat+Pin.swift"; path = "Util/CGFloat+Pin.swift"; sourceTree = ""; }; 33 | BE5C1E3E1F32710B00B0080C /* HSBComponent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = HSBComponent.swift; path = Model/HSBComponent.swift; sourceTree = ""; }; 34 | BE5C1E401F3271D600B0080C /* ColorBarPicker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ColorBarPicker.swift; path = View/ColorBarPicker.swift; sourceTree = ""; }; 35 | BE5C1E411F3271D600B0080C /* ColorBarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ColorBarView.swift; path = View/ColorBarView.swift; sourceTree = ""; }; 36 | BE5C1E421F3271D600B0080C /* ColorIndicatorView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ColorIndicatorView.swift; path = View/ColorIndicatorView.swift; sourceTree = ""; }; 37 | BE5C1E431F3271D600B0080C /* ColorSquarePicker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ColorSquarePicker.swift; path = View/ColorSquarePicker.swift; sourceTree = ""; }; 38 | BE5C1E441F3271D600B0080C /* ColorSquareView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ColorSquareView.swift; path = View/ColorSquareView.swift; sourceTree = ""; }; 39 | BE5C1E461F3271D600B0080C /* SourceColorView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SourceColorView.swift; path = View/SourceColorView.swift; sourceTree = ""; }; 40 | BE5C1E4E1F3271E900B0080C /* HSBGen.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = HSBGen.swift; path = Util/HSBGen.swift; sourceTree = ""; }; 41 | /* End PBXFileReference section */ 42 | 43 | /* Begin PBXFrameworksBuildPhase section */ 44 | BE5C1E131F3266B600B0080C /* Frameworks */ = { 45 | isa = PBXFrameworksBuildPhase; 46 | buildActionMask = 2147483647; 47 | files = ( 48 | ); 49 | runOnlyForDeploymentPostprocessing = 0; 50 | }; 51 | /* End PBXFrameworksBuildPhase section */ 52 | 53 | /* Begin PBXGroup section */ 54 | BE5C1E0D1F3266B600B0080C = { 55 | isa = PBXGroup; 56 | children = ( 57 | BE5C1E191F3266B600B0080C /* HueKit */, 58 | BE5C1E181F3266B600B0080C /* Products */, 59 | ); 60 | sourceTree = ""; 61 | }; 62 | BE5C1E181F3266B600B0080C /* Products */ = { 63 | isa = PBXGroup; 64 | children = ( 65 | BE5C1E171F3266B600B0080C /* HueKit.framework */, 66 | ); 67 | name = Products; 68 | sourceTree = ""; 69 | }; 70 | BE5C1E191F3266B600B0080C /* HueKit */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | BE5C1E391F326E9300B0080C /* Util */, 74 | BE5C1E221F326BF500B0080C /* Model */, 75 | BE5C1E231F326BFD00B0080C /* View */, 76 | BE5C1E1A1F3266B600B0080C /* HueKit.h */, 77 | BE5C1E1B1F3266B600B0080C /* Info.plist */, 78 | ); 79 | path = HueKit; 80 | sourceTree = ""; 81 | }; 82 | BE5C1E221F326BF500B0080C /* Model */ = { 83 | isa = PBXGroup; 84 | children = ( 85 | BE5C1E351F326E2500B0080C /* RGB.swift */, 86 | BE5C1E371F326E3300B0080C /* HSV.swift */, 87 | BE5C1E3E1F32710B00B0080C /* HSBComponent.swift */, 88 | ); 89 | name = Model; 90 | sourceTree = ""; 91 | }; 92 | BE5C1E231F326BFD00B0080C /* View */ = { 93 | isa = PBXGroup; 94 | children = ( 95 | BE5C1E401F3271D600B0080C /* ColorBarPicker.swift */, 96 | BE5C1E411F3271D600B0080C /* ColorBarView.swift */, 97 | BE5C1E421F3271D600B0080C /* ColorIndicatorView.swift */, 98 | BE5C1E431F3271D600B0080C /* ColorSquarePicker.swift */, 99 | BE5C1E441F3271D600B0080C /* ColorSquareView.swift */, 100 | BE5C1E461F3271D600B0080C /* SourceColorView.swift */, 101 | ); 102 | name = View; 103 | sourceTree = ""; 104 | }; 105 | BE5C1E391F326E9300B0080C /* Util */ = { 106 | isa = PBXGroup; 107 | children = ( 108 | BE5C1E4E1F3271E900B0080C /* HSBGen.swift */, 109 | BE5C1E3A1F326EE600B0080C /* UIColor+Values.swift */, 110 | BE5C1E3C1F3270CE00B0080C /* CGFloat+Pin.swift */, 111 | ); 112 | name = Util; 113 | sourceTree = ""; 114 | }; 115 | /* End PBXGroup section */ 116 | 117 | /* Begin PBXHeadersBuildPhase section */ 118 | BE5C1E141F3266B600B0080C /* Headers */ = { 119 | isa = PBXHeadersBuildPhase; 120 | buildActionMask = 2147483647; 121 | files = ( 122 | BE5C1E1C1F3266B600B0080C /* HueKit.h in Headers */, 123 | ); 124 | runOnlyForDeploymentPostprocessing = 0; 125 | }; 126 | /* End PBXHeadersBuildPhase section */ 127 | 128 | /* Begin PBXNativeTarget section */ 129 | BE5C1E161F3266B600B0080C /* HueKit */ = { 130 | isa = PBXNativeTarget; 131 | buildConfigurationList = BE5C1E1F1F3266B600B0080C /* Build configuration list for PBXNativeTarget "HueKit" */; 132 | buildPhases = ( 133 | BE5C1E121F3266B600B0080C /* Sources */, 134 | BE5C1E131F3266B600B0080C /* Frameworks */, 135 | BE5C1E141F3266B600B0080C /* Headers */, 136 | BE5C1E151F3266B600B0080C /* Resources */, 137 | ); 138 | buildRules = ( 139 | ); 140 | dependencies = ( 141 | ); 142 | name = HueKit; 143 | productName = HueKit; 144 | productReference = BE5C1E171F3266B600B0080C /* HueKit.framework */; 145 | productType = "com.apple.product-type.framework"; 146 | }; 147 | /* End PBXNativeTarget section */ 148 | 149 | /* Begin PBXProject section */ 150 | BE5C1E0E1F3266B600B0080C /* Project object */ = { 151 | isa = PBXProject; 152 | attributes = { 153 | LastSwiftUpdateCheck = 0930; 154 | LastUpgradeCheck = 0930; 155 | ORGANIZATIONNAME = "Silver Fox"; 156 | TargetAttributes = { 157 | BE5C1E161F3266B600B0080C = { 158 | CreatedOnToolsVersion = 8.3.3; 159 | LastSwiftMigration = 0900; 160 | ProvisioningStyle = Manual; 161 | }; 162 | }; 163 | }; 164 | buildConfigurationList = BE5C1E111F3266B600B0080C /* Build configuration list for PBXProject "HueKit" */; 165 | compatibilityVersion = "Xcode 3.2"; 166 | developmentRegion = English; 167 | hasScannedForEncodings = 0; 168 | knownRegions = ( 169 | en, 170 | Base, 171 | ); 172 | mainGroup = BE5C1E0D1F3266B600B0080C; 173 | productRefGroup = BE5C1E181F3266B600B0080C /* Products */; 174 | projectDirPath = ""; 175 | projectRoot = ""; 176 | targets = ( 177 | BE5C1E161F3266B600B0080C /* HueKit */, 178 | ); 179 | }; 180 | /* End PBXProject section */ 181 | 182 | /* Begin PBXResourcesBuildPhase section */ 183 | BE5C1E151F3266B600B0080C /* Resources */ = { 184 | isa = PBXResourcesBuildPhase; 185 | buildActionMask = 2147483647; 186 | files = ( 187 | ); 188 | runOnlyForDeploymentPostprocessing = 0; 189 | }; 190 | /* End PBXResourcesBuildPhase section */ 191 | 192 | /* Begin PBXSourcesBuildPhase section */ 193 | BE5C1E121F3266B600B0080C /* Sources */ = { 194 | isa = PBXSourcesBuildPhase; 195 | buildActionMask = 2147483647; 196 | files = ( 197 | BE5C1E3B1F326EE600B0080C /* UIColor+Values.swift in Sources */, 198 | BE5C1E471F3271D600B0080C /* ColorBarPicker.swift in Sources */, 199 | BE5C1E4F1F3271E900B0080C /* HSBGen.swift in Sources */, 200 | BE5C1E4D1F3271D600B0080C /* SourceColorView.swift in Sources */, 201 | BE5C1E4A1F3271D600B0080C /* ColorSquarePicker.swift in Sources */, 202 | BE5C1E491F3271D600B0080C /* ColorIndicatorView.swift in Sources */, 203 | BE5C1E381F326E3300B0080C /* HSV.swift in Sources */, 204 | BE5C1E3F1F32710B00B0080C /* HSBComponent.swift in Sources */, 205 | BE5C1E361F326E2500B0080C /* RGB.swift in Sources */, 206 | BE5C1E4B1F3271D600B0080C /* ColorSquareView.swift in Sources */, 207 | BE5C1E3D1F3270CE00B0080C /* CGFloat+Pin.swift in Sources */, 208 | BE5C1E481F3271D600B0080C /* ColorBarView.swift in Sources */, 209 | ); 210 | runOnlyForDeploymentPostprocessing = 0; 211 | }; 212 | /* End PBXSourcesBuildPhase section */ 213 | 214 | /* Begin XCBuildConfiguration section */ 215 | BE5C1E1D1F3266B600B0080C /* Debug */ = { 216 | isa = XCBuildConfiguration; 217 | buildSettings = { 218 | ALWAYS_SEARCH_USER_PATHS = NO; 219 | CLANG_ANALYZER_NONNULL = YES; 220 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 221 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 222 | CLANG_CXX_LIBRARY = "libc++"; 223 | CLANG_ENABLE_MODULES = YES; 224 | CLANG_ENABLE_OBJC_ARC = YES; 225 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 226 | CLANG_WARN_BOOL_CONVERSION = YES; 227 | CLANG_WARN_COMMA = YES; 228 | CLANG_WARN_CONSTANT_CONVERSION = YES; 229 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 230 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 231 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 232 | CLANG_WARN_EMPTY_BODY = YES; 233 | CLANG_WARN_ENUM_CONVERSION = YES; 234 | CLANG_WARN_INFINITE_RECURSION = YES; 235 | CLANG_WARN_INT_CONVERSION = YES; 236 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 237 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 238 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 239 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 240 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 241 | CLANG_WARN_STRICT_PROTOTYPES = YES; 242 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 243 | CLANG_WARN_UNREACHABLE_CODE = YES; 244 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 245 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 246 | COPY_PHASE_STRIP = NO; 247 | CURRENT_PROJECT_VERSION = 1; 248 | DEBUG_INFORMATION_FORMAT = dwarf; 249 | ENABLE_STRICT_OBJC_MSGSEND = YES; 250 | ENABLE_TESTABILITY = YES; 251 | GCC_C_LANGUAGE_STANDARD = gnu99; 252 | GCC_DYNAMIC_NO_PIC = NO; 253 | GCC_NO_COMMON_BLOCKS = YES; 254 | GCC_OPTIMIZATION_LEVEL = 0; 255 | GCC_PREPROCESSOR_DEFINITIONS = ( 256 | "DEBUG=1", 257 | "$(inherited)", 258 | ); 259 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 260 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 261 | GCC_WARN_UNDECLARED_SELECTOR = YES; 262 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 263 | GCC_WARN_UNUSED_FUNCTION = YES; 264 | GCC_WARN_UNUSED_VARIABLE = YES; 265 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 266 | MTL_ENABLE_DEBUG_INFO = YES; 267 | ONLY_ACTIVE_ARCH = YES; 268 | SDKROOT = iphoneos; 269 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 270 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 271 | TARGETED_DEVICE_FAMILY = "1,2"; 272 | VERSIONING_SYSTEM = "apple-generic"; 273 | VERSION_INFO_PREFIX = ""; 274 | }; 275 | name = Debug; 276 | }; 277 | BE5C1E1E1F3266B600B0080C /* Release */ = { 278 | isa = XCBuildConfiguration; 279 | buildSettings = { 280 | ALWAYS_SEARCH_USER_PATHS = NO; 281 | CLANG_ANALYZER_NONNULL = YES; 282 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 283 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 284 | CLANG_CXX_LIBRARY = "libc++"; 285 | CLANG_ENABLE_MODULES = YES; 286 | CLANG_ENABLE_OBJC_ARC = YES; 287 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 288 | CLANG_WARN_BOOL_CONVERSION = YES; 289 | CLANG_WARN_COMMA = YES; 290 | CLANG_WARN_CONSTANT_CONVERSION = YES; 291 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 292 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 293 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 294 | CLANG_WARN_EMPTY_BODY = YES; 295 | CLANG_WARN_ENUM_CONVERSION = YES; 296 | CLANG_WARN_INFINITE_RECURSION = YES; 297 | CLANG_WARN_INT_CONVERSION = YES; 298 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 299 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 300 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 301 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 302 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 303 | CLANG_WARN_STRICT_PROTOTYPES = YES; 304 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 305 | CLANG_WARN_UNREACHABLE_CODE = YES; 306 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 307 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 308 | COPY_PHASE_STRIP = NO; 309 | CURRENT_PROJECT_VERSION = 1; 310 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 311 | ENABLE_NS_ASSERTIONS = NO; 312 | ENABLE_STRICT_OBJC_MSGSEND = YES; 313 | GCC_C_LANGUAGE_STANDARD = gnu99; 314 | GCC_NO_COMMON_BLOCKS = YES; 315 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 316 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 317 | GCC_WARN_UNDECLARED_SELECTOR = YES; 318 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 319 | GCC_WARN_UNUSED_FUNCTION = YES; 320 | GCC_WARN_UNUSED_VARIABLE = YES; 321 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 322 | MTL_ENABLE_DEBUG_INFO = NO; 323 | SDKROOT = iphoneos; 324 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 325 | TARGETED_DEVICE_FAMILY = "1,2"; 326 | VALIDATE_PRODUCT = YES; 327 | VERSIONING_SYSTEM = "apple-generic"; 328 | VERSION_INFO_PREFIX = ""; 329 | }; 330 | name = Release; 331 | }; 332 | BE5C1E201F3266B600B0080C /* Debug */ = { 333 | isa = XCBuildConfiguration; 334 | buildSettings = { 335 | CLANG_ENABLE_MODULES = YES; 336 | CODE_SIGN_IDENTITY = ""; 337 | CODE_SIGN_STYLE = Manual; 338 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 339 | DEFINES_MODULE = YES; 340 | DEVELOPMENT_TEAM = ""; 341 | DYLIB_COMPATIBILITY_VERSION = 1; 342 | DYLIB_CURRENT_VERSION = 1; 343 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 344 | INFOPLIST_FILE = HueKit/Info.plist; 345 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 346 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 347 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 348 | PRODUCT_BUNDLE_IDENTIFIER = be.silverfox.HueKit; 349 | PRODUCT_NAME = "$(TARGET_NAME)"; 350 | PROVISIONING_PROFILE_SPECIFIER = ""; 351 | SKIP_INSTALL = YES; 352 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 353 | SWIFT_SWIFT3_OBJC_INFERENCE = Default; 354 | SWIFT_VERSION = 4.0; 355 | }; 356 | name = Debug; 357 | }; 358 | BE5C1E211F3266B600B0080C /* Release */ = { 359 | isa = XCBuildConfiguration; 360 | buildSettings = { 361 | CLANG_ENABLE_MODULES = YES; 362 | CODE_SIGN_IDENTITY = ""; 363 | CODE_SIGN_STYLE = Manual; 364 | DEFINES_MODULE = YES; 365 | DEVELOPMENT_TEAM = ""; 366 | DYLIB_COMPATIBILITY_VERSION = 1; 367 | DYLIB_CURRENT_VERSION = 1; 368 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 369 | INFOPLIST_FILE = HueKit/Info.plist; 370 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 371 | IPHONEOS_DEPLOYMENT_TARGET = 10.0; 372 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 373 | PRODUCT_BUNDLE_IDENTIFIER = be.silverfox.HueKit; 374 | PRODUCT_NAME = "$(TARGET_NAME)"; 375 | PROVISIONING_PROFILE_SPECIFIER = ""; 376 | SKIP_INSTALL = YES; 377 | SWIFT_SWIFT3_OBJC_INFERENCE = Default; 378 | SWIFT_VERSION = 4.0; 379 | }; 380 | name = Release; 381 | }; 382 | /* End XCBuildConfiguration section */ 383 | 384 | /* Begin XCConfigurationList section */ 385 | BE5C1E111F3266B600B0080C /* Build configuration list for PBXProject "HueKit" */ = { 386 | isa = XCConfigurationList; 387 | buildConfigurations = ( 388 | BE5C1E1D1F3266B600B0080C /* Debug */, 389 | BE5C1E1E1F3266B600B0080C /* Release */, 390 | ); 391 | defaultConfigurationIsVisible = 0; 392 | defaultConfigurationName = Release; 393 | }; 394 | BE5C1E1F1F3266B600B0080C /* Build configuration list for PBXNativeTarget "HueKit" */ = { 395 | isa = XCConfigurationList; 396 | buildConfigurations = ( 397 | BE5C1E201F3266B600B0080C /* Debug */, 398 | BE5C1E211F3266B600B0080C /* Release */, 399 | ); 400 | defaultConfigurationIsVisible = 0; 401 | defaultConfigurationName = Release; 402 | }; 403 | /* End XCConfigurationList section */ 404 | }; 405 | rootObject = BE5C1E0E1F3266B600B0080C /* Project object */; 406 | } 407 | -------------------------------------------------------------------------------- /HueKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /HueKit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /HueKit.xcodeproj/xcshareddata/xcschemes/HueKit.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /HueKit.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /HueKit.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /HueKit/HueKit.h: -------------------------------------------------------------------------------- 1 | // 2 | // HueKit.h 3 | // HueKit 4 | // 5 | // Created by Louis D'hauwe on 02/08/2017. 6 | // Copyright © 2017 Silver Fox. All rights reserved. 7 | // 8 | -------------------------------------------------------------------------------- /HueKit/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 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.0.1 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | NSPrincipalClass 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /HueKit/Model/HSBComponent.swift: -------------------------------------------------------------------------------- 1 | // 2 | // HSBComponent.swift 3 | // HueKit 4 | // 5 | // Created by Louis D'hauwe on 02/08/2017. 6 | // Copyright © 2017 Silver Fox. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | enum HSBComponent: Int { 12 | case hue = 0 13 | case saturation = 1 14 | case brightness = 2 15 | } 16 | -------------------------------------------------------------------------------- /HueKit/Model/HSV.swift: -------------------------------------------------------------------------------- 1 | // 2 | // HSV.swift 3 | // HueKit 4 | // 5 | // Created by Louis D'hauwe on 02/08/2017. 6 | // Copyright © 2017 Silver Fox. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import CoreGraphics 11 | 12 | public struct HSV: Hashable { 13 | /// In degrees (range 0...360) 14 | public var h: CGFloat 15 | 16 | /// Percentage in range 0...1 17 | public var s: CGFloat 18 | 19 | /// Percentage in range 0...1 20 | /// Also known as "brightness" (B) 21 | public var v: CGFloat 22 | } 23 | 24 | extension HSV { 25 | 26 | /// These functions convert between an RGB value with components in the 27 | /// 0.0..1.0 range to HSV where Hue is 0 .. 360 and Saturation and 28 | /// Value (aka Brightness) are percentages expressed as 0.0..1.0. 29 | // 30 | /// Note that HSB (B = Brightness) and HSV (V = Value) are interchangeable 31 | /// names that mean the same thing. I use V here as it is unambiguous 32 | /// relative to the B in RGB, which is Blue. 33 | func toRGB() -> RGB { 34 | 35 | var rgb = self.hueToRGB() 36 | 37 | let c = v * s 38 | let m = v - c 39 | 40 | rgb.r = rgb.r * c + m 41 | rgb.g = rgb.g * c + m 42 | rgb.b = rgb.b * c + m 43 | 44 | return rgb 45 | } 46 | 47 | func hueToRGB() -> RGB { 48 | 49 | let hPrime = h / 60.0 50 | 51 | let x = 1.0 - abs(hPrime.truncatingRemainder(dividingBy: 2.0) - 1.0) 52 | 53 | let r: CGFloat 54 | let g: CGFloat 55 | let b: CGFloat 56 | 57 | if hPrime < 1.0 { 58 | 59 | r = 1 60 | g = x 61 | b = 0 62 | 63 | } else if hPrime < 2.0 { 64 | 65 | r = x 66 | g = 1 67 | b = 0 68 | 69 | } else if hPrime < 3.0 { 70 | 71 | r = 0 72 | g = 1 73 | b = x 74 | 75 | } else if hPrime < 4.0 { 76 | 77 | r = 0 78 | g = x 79 | b = 1 80 | 81 | } else if hPrime < 5.0 { 82 | 83 | r = x 84 | g = 0 85 | b = 1 86 | 87 | } else { 88 | 89 | r = 1 90 | g = 0 91 | b = x 92 | 93 | } 94 | 95 | return RGB(r: r, g: g, b: b) 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /HueKit/Model/RGB.swift: -------------------------------------------------------------------------------- 1 | // 2 | // RGB.swift 3 | // HueKit 4 | // 5 | // Created by Louis D'hauwe on 02/08/2017. 6 | // Copyright © 2017 Silver Fox. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import CoreGraphics 11 | 12 | public struct RGB: Hashable { 13 | /// In range 0...1 14 | public var r: CGFloat 15 | 16 | /// In range 0...1 17 | public var g: CGFloat 18 | 19 | /// In range 0...1 20 | public var b: CGFloat 21 | } 22 | 23 | public extension RGB { 24 | 25 | func toHSV(preserveHS: Bool, h: CGFloat = 0, s: CGFloat = 0) -> HSV { 26 | 27 | var h = h 28 | var s = s 29 | var v: CGFloat = 0 30 | 31 | var max = r 32 | 33 | if max < g { 34 | max = g 35 | } 36 | 37 | if max < b { 38 | max = b 39 | } 40 | 41 | var min = r 42 | 43 | if min > g { 44 | min = g 45 | } 46 | 47 | if min > b { 48 | min = b 49 | } 50 | 51 | // Brightness (aka Value) 52 | 53 | v = max 54 | 55 | // Saturation 56 | 57 | var sat: CGFloat = 0.0 58 | 59 | if max != 0.0 { 60 | 61 | sat = (max - min) / max 62 | s = sat 63 | 64 | } else { 65 | 66 | sat = 0.0 67 | 68 | // Black, so sat is undefined, use 0 69 | if !preserveHS { 70 | s = 0.0 71 | } 72 | } 73 | 74 | // Hue 75 | 76 | var delta: CGFloat = 0 77 | 78 | if sat == 0.0 { 79 | 80 | // No color, so hue is undefined, use 0 81 | if !preserveHS { 82 | h = 0.0 83 | } 84 | 85 | } else { 86 | 87 | delta = max - min 88 | 89 | var hue: CGFloat = 0 90 | 91 | if r == max { 92 | hue = (g - b) / delta 93 | } else if g == max { 94 | hue = 2 + (b - r) / delta 95 | } else { 96 | hue = 4 + (r - g) / delta 97 | } 98 | 99 | hue /= 6.0 100 | 101 | if hue < 0.0 { 102 | hue += 1.0 103 | } 104 | 105 | // 0.0 and 1.0 hues are actually both the same (red) 106 | if !preserveHS || abs(hue - h) != 1.0 { 107 | h = hue 108 | } 109 | } 110 | 111 | return HSV(h: h, s: s, v: v) 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /HueKit/Util/CGFloat+Pin.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CGFloat+Pin.swift 3 | // HueKit 4 | // 5 | // Created by Louis D'hauwe on 02/08/2017. 6 | // Copyright © 2017 Silver Fox. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import CoreGraphics 11 | 12 | extension CGFloat { 13 | 14 | func pinned(between minValue: CGFloat, and maxValue: CGFloat) -> CGFloat { 15 | 16 | if self < minValue { 17 | return minValue 18 | } else if self > maxValue { 19 | return maxValue 20 | } else { 21 | return self 22 | } 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /HueKit/Util/HSBGen.swift: -------------------------------------------------------------------------------- 1 | // 2 | // HSBGen.swift 3 | // HueKit 4 | // 5 | // Created by Louis D'hauwe on 29/07/2017. 6 | // Copyright © 2017 Silver Fox. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import CoreGraphics 11 | 12 | class HSBGen { 13 | 14 | static func createBGRxImageContext(w: Int, h: Int) -> CGContext? { 15 | 16 | let colorSpace = CGColorSpaceCreateDeviceRGB() 17 | 18 | // BGRA is the most efficient on the iPhone. 19 | var bitmapInfo = CGBitmapInfo(rawValue: CGImageByteOrderInfo.order32Little.rawValue) 20 | 21 | let noneSkipFirst = CGBitmapInfo(rawValue: CGImageAlphaInfo.noneSkipFirst.rawValue) 22 | 23 | bitmapInfo.formUnion(noneSkipFirst) 24 | 25 | let context = CGContext(data: nil, width: w, height: h, bitsPerComponent: 8, bytesPerRow: w * 4, space: colorSpace, bitmapInfo: bitmapInfo.rawValue) 26 | 27 | return context 28 | } 29 | 30 | /// Generates an image where the specified barComponentIndex (0=H, 1=S, 2=V) 31 | /// varies across the x-axis of the 256x1 pixel image and the other components 32 | /// remain at the constant value specified in the hsv array. 33 | static func createHSVBarContentImage(hsbComponent: HSBComponent, hsv: [CGFloat]) -> CGImage? { 34 | 35 | var hsv = hsv 36 | 37 | guard let context = createBGRxImageContext(w: 256, h: 1) else { 38 | return nil 39 | } 40 | 41 | guard var ptr = context.data?.assumingMemoryBound(to: UInt8.self) else { 42 | return nil 43 | } 44 | 45 | for x in 0..<256 { 46 | 47 | hsv[hsbComponent.rawValue] = CGFloat(x) / 255.0 48 | 49 | let hsvVal = HSV(h: hsv[0] * 360.0, s: hsv[1], v: hsv[2]) 50 | 51 | let rgb = hsvVal.toRGB() 52 | 53 | ptr[0] = UInt8(rgb.b * 255.0) 54 | ptr[1] = UInt8(rgb.g * 255.0) 55 | ptr[2] = UInt8(rgb.r * 255.0) 56 | 57 | ptr = ptr.advanced(by: 4) 58 | } 59 | 60 | let image = context.makeImage() 61 | 62 | return image 63 | } 64 | 65 | static private func blend(_ value: UInt, _ percentIn255: UInt) -> UInt { 66 | return (value) * (percentIn255) / 255 67 | } 68 | 69 | // Generates a 256x256 image with the specified constant hue where the 70 | // Saturation and value vary in the X and Y axes respectively. 71 | static func createSaturationBrightnessSquareContentImageWithHue(hue: CGFloat) -> CGImage? { 72 | 73 | guard let context = createBGRxImageContext(w: 256, h: 256) else { 74 | return nil 75 | } 76 | 77 | guard var dataPtr = context.data?.assumingMemoryBound(to: UInt8.self) else { 78 | return nil 79 | } 80 | 81 | let rowBytes = context.bytesPerRow 82 | 83 | let hsv = HSV(h: hue, s: 0, v: 0) 84 | let rgb = hsv.hueToRGB() 85 | 86 | let r = rgb.r 87 | let g = rgb.g 88 | let b = rgb.b 89 | 90 | let r_s = (UInt) ((1.0 - r) * 255) 91 | let g_s = (UInt) ((1.0 - g) * 255) 92 | let b_s = (UInt) ((1.0 - b) * 255) 93 | 94 | // This doesn't use Swift ranges because those are pretty slow in debug builds 95 | 96 | var s: UInt = 0 97 | 98 | while true { 99 | 100 | var ptr = dataPtr 101 | 102 | let r_hs: UInt = 255 - blend(s, r_s) 103 | let g_hs: UInt = 255 - blend(s, g_s) 104 | let b_hs: UInt = 255 - blend(s, b_s) 105 | 106 | var v: UInt = 255 107 | 108 | while true { 109 | 110 | // Really, these should all be of the form used in blend(), 111 | // which does a divide by 255. However, integer divide is 112 | // implemented in software on ARM, so a divide by 256 113 | // (done as a bit shift) will be *nearly* the same value, 114 | // and is faster. The more-accurate versions would look like: 115 | // ptr[0] = blend(v, b_hs); 116 | 117 | ptr[0] = UInt8((v * b_hs) >> 8) 118 | ptr[1] = UInt8((v * g_hs) >> 8) 119 | ptr[2] = UInt8((v * r_hs) >> 8) 120 | 121 | ptr = ptr.advanced(by: rowBytes) 122 | 123 | if v == 0 { 124 | break 125 | } 126 | 127 | v -= 1 128 | } 129 | 130 | dataPtr = dataPtr.advanced(by: 4) 131 | 132 | if s == 255 { 133 | break 134 | } 135 | 136 | s += 1 137 | } 138 | 139 | let image = context.makeImage() 140 | 141 | return image 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /HueKit/Util/UIColor+Values.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIColor+Values.swift 3 | // HueKit 4 | // 5 | // Created by Louis D'hauwe on 02/08/2017. 6 | // Copyright © 2017 Silver Fox. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | extension UIColor { 13 | 14 | public var rgbValue: RGB? { 15 | 16 | guard let components = cgColor.components else { 17 | return nil 18 | } 19 | 20 | let numComponents = cgColor.numberOfComponents 21 | 22 | let r: CGFloat 23 | let g: CGFloat 24 | let b: CGFloat 25 | 26 | if numComponents < 3 { 27 | r = components[0] 28 | g = components[0] 29 | b = components[0] 30 | } else { 31 | r = components[0] 32 | g = components[1] 33 | b = components[2] 34 | } 35 | 36 | return RGB(r: r, g: g, b: b) 37 | } 38 | 39 | public var hsvValue: HSV? { 40 | 41 | guard let rgb = rgbValue else { 42 | return nil 43 | } 44 | 45 | return rgb.toHSV(preserveHS: true) 46 | } 47 | 48 | public func hsvValue(preservingHue hue: CGFloat, preservingSat sat: CGFloat) -> HSV? { 49 | 50 | guard let rgb = rgbValue else { 51 | return nil 52 | } 53 | 54 | return rgb.toHSV(preserveHS: true, h: hue, s: sat) 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /HueKit/View/ColorBarPicker.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ColorBarPicker.swift 3 | // HueKit 4 | // 5 | // Created by Louis D'hauwe on 30/07/2017. 6 | // Copyright © 2017 Silver Fox. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | @IBDesignable 13 | open class ColorBarPicker: UIControl { 14 | 15 | private var isVertical: Bool = false { 16 | didSet { 17 | if isVertical != oldValue { 18 | updateOrientation() 19 | } 20 | } 21 | } 22 | 23 | private func updateVerticalState() { 24 | 25 | // let bounds = self.layer.presentation()?.bounds ?? self.bounds 26 | isVertical = bounds.height > bounds.width 27 | 28 | } 29 | 30 | 31 | private let contentInset: CGFloat = 20.0 32 | private static let indicatorSizeInactive = CGSize(width: 24.0, height: 24.0) 33 | private static let indicatorSizeActive = CGSize(width: 40.0, height: 40.0) 34 | 35 | @IBInspectable 36 | open var hue: CGFloat { 37 | get { 38 | if isVertical { 39 | return 1.0 - value 40 | } else { 41 | return value 42 | } 43 | } 44 | set { 45 | if isVertical { 46 | value = 1.0 - newValue 47 | } else { 48 | value = newValue 49 | } 50 | } 51 | } 52 | 53 | private var value: CGFloat = 0.0 { 54 | didSet { 55 | 56 | if oldValue != value { 57 | 58 | self.sendActions(for: .valueChanged) 59 | self.setNeedsLayout() 60 | } 61 | 62 | } 63 | } 64 | 65 | open lazy var colorBarView: ColorBarView = { 66 | return ColorBarView() 67 | }() 68 | 69 | private lazy var indicator: ColorIndicatorView = { 70 | 71 | let frame = CGRect(origin: .zero, size: ColorBarPicker.indicatorSizeInactive) 72 | let indicator = ColorIndicatorView(frame: frame) 73 | 74 | return indicator 75 | 76 | }() 77 | 78 | func updateOrientation() { 79 | 80 | guard colorBarView.superview != nil else { 81 | return 82 | } 83 | 84 | if isVertical { 85 | 86 | colorBarView.transform = .identity 87 | 88 | var rect = self.bounds 89 | rect.size.width = bounds.height - contentInset * 2 90 | rect.size.height = bounds.width 91 | 92 | colorBarView.frame = rect 93 | 94 | colorBarView.transform = CGAffineTransform(rotationAngle: -.pi / 2.0) 95 | 96 | colorBarView.frame.origin = CGPoint(x: 0, y: contentInset) 97 | 98 | } else { 99 | 100 | var rect = self.bounds 101 | rect.size.width -= contentInset * 2 102 | 103 | colorBarView.frame = rect 104 | 105 | colorBarView.transform = .identity 106 | 107 | colorBarView.frame.origin = CGPoint(x: contentInset, y: 0) 108 | 109 | } 110 | 111 | } 112 | 113 | // MARK: - Drawing 114 | 115 | override open func layoutSubviews() { 116 | 117 | if colorBarView.superview == nil { 118 | 119 | colorBarView.isUserInteractionEnabled = false 120 | 121 | colorBarView.translatesAutoresizingMaskIntoConstraints = false 122 | self.addSubview(colorBarView) 123 | 124 | updateOrientation() 125 | 126 | } 127 | 128 | if indicator.superview == nil { 129 | self.addSubview(indicator) 130 | } 131 | 132 | let wasVertical = isVertical 133 | 134 | updateVerticalState() 135 | 136 | if wasVertical != isVertical { 137 | 138 | value = 1.0 - value 139 | 140 | } 141 | 142 | updateOrientation() 143 | // colorBarView.setNeedsDisplay() 144 | 145 | indicator.color = UIColor(hue: hue, 146 | saturation: 1.0, 147 | brightness: 1.0, 148 | alpha: 1.0) 149 | 150 | if isVertical { 151 | 152 | let indicatorLoc = contentInset + (self.value * (self.bounds.size.height - 2 * contentInset)) 153 | indicator.center = CGPoint(x: self.bounds.midX, y: indicatorLoc) 154 | 155 | } else { 156 | 157 | let indicatorLoc = contentInset + (self.value * (self.bounds.size.width - 2 * contentInset)) 158 | indicator.center = CGPoint(x: indicatorLoc, y: self.bounds.midY) 159 | 160 | } 161 | 162 | } 163 | 164 | // MARK: - Tracking 165 | 166 | private func trackIndicator(with touch: UITouch) { 167 | 168 | let touchLocation = touch.location(in: self) 169 | 170 | let percent: CGFloat 171 | 172 | if isVertical { 173 | 174 | percent = (touchLocation.y - contentInset) / (self.bounds.size.height - 2 * contentInset) 175 | 176 | } else { 177 | 178 | percent = (touchLocation.x - contentInset) / (self.bounds.size.width - 2 * contentInset) 179 | 180 | } 181 | 182 | self.value = percent.pinned(between: 0, and: 1) 183 | } 184 | 185 | override open func beginTracking(_ touch: UITouch, with event: UIEvent?) -> Bool { 186 | self.trackIndicator(with: touch) 187 | 188 | growIndicator() 189 | return true 190 | } 191 | 192 | override open func continueTracking(_ touch: UITouch, with event: UIEvent?) -> Bool { 193 | self.trackIndicator(with: touch) 194 | 195 | return true 196 | } 197 | 198 | override open func endTracking(_ touch: UITouch?, with event: UIEvent?) { 199 | super.endTracking(touch, with: event) 200 | 201 | shrinkIndicator() 202 | } 203 | 204 | override open func cancelTracking(with event: UIEvent?) { 205 | super.cancelTracking(with: event) 206 | 207 | shrinkIndicator() 208 | } 209 | 210 | private func changeIndicatorSize(to size: CGSize) { 211 | 212 | let center = self.indicator.center 213 | 214 | let indicatorRect = CGRect(origin: .zero, size: size) 215 | 216 | self.indicator.frame = indicatorRect 217 | self.indicator.center = center 218 | 219 | } 220 | 221 | private func growIndicator() { 222 | 223 | UIView.animate(withDuration: 0.15, delay: 0.0, options: [.curveEaseIn], animations: { 224 | 225 | self.changeIndicatorSize(to: ColorBarPicker.indicatorSizeActive) 226 | 227 | }) { (finished) in 228 | 229 | } 230 | 231 | } 232 | 233 | private func shrinkIndicator() { 234 | 235 | UIView.animate(withDuration: 0.15, delay: 0.0, options: [.curveEaseOut], animations: { 236 | 237 | self.changeIndicatorSize(to: ColorBarPicker.indicatorSizeInactive) 238 | self.indicator.setNeedsDisplay() 239 | 240 | }) { (finished) in 241 | 242 | self.indicator.setNeedsDisplay() 243 | 244 | } 245 | 246 | } 247 | 248 | 249 | // MARK: - Accessibility 250 | 251 | private let accessibilityInterval: CGFloat = 0.05 252 | 253 | open override var accessibilityTraits: UIAccessibilityTraits { 254 | get { 255 | var t = super.accessibilityTraits 256 | 257 | t |= UIAccessibilityTraitAdjustable 258 | 259 | return t 260 | } 261 | set { 262 | super.accessibilityTraits = newValue 263 | } 264 | } 265 | 266 | open override func accessibilityIncrement() { 267 | 268 | var newValue = self.value + accessibilityInterval 269 | 270 | if newValue > 1.0 { 271 | newValue -= 1.0 272 | } 273 | 274 | self.value = newValue 275 | } 276 | 277 | open override func accessibilityDecrement() { 278 | 279 | var newValue = self.value - accessibilityInterval 280 | 281 | if newValue < 0 { 282 | newValue += 1.0 283 | } 284 | 285 | self.value = newValue 286 | } 287 | 288 | open override var accessibilityValue: String? { 289 | get { 290 | return String(format: "%d degrees hue", (self.value * 360.0)) 291 | } 292 | set { 293 | super.accessibilityValue = newValue 294 | } 295 | } 296 | 297 | } 298 | -------------------------------------------------------------------------------- /HueKit/View/ColorBarView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ColorBarView.swift 3 | // HueKit 4 | // 5 | // Created by Louis D'hauwe on 29/07/2017. 6 | // Copyright © 2017 Silver Fox. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | @IBDesignable 13 | open class ColorBarView: UIView { 14 | 15 | private static func createContentImage() -> CGImage? { 16 | 17 | let hsv: [CGFloat] = [0.0, 1.0, 1.0] 18 | 19 | return HSBGen.createHSVBarContentImage(hsbComponent: .hue, hsv: hsv) 20 | } 21 | 22 | override open func draw(_ rect: CGRect) { 23 | 24 | guard let context = UIGraphicsGetCurrentContext() else { 25 | return 26 | } 27 | 28 | guard let image = ColorBarView.createContentImage() else { 29 | return 30 | } 31 | 32 | context.draw(image, in: self.bounds) 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /HueKit/View/ColorIndicatorView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ColorIndicatorView.swift 3 | // HueKit 4 | // 5 | // Created by Louis D'hauwe on 30/07/2017. 6 | // Copyright © 2017 Silver Fox. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | @IBDesignable 13 | open class ColorIndicatorView: UIView { 14 | 15 | @IBInspectable 16 | open var color: UIColor = .black { 17 | didSet { 18 | 19 | if oldValue != color { 20 | self.setNeedsDisplay() 21 | } 22 | 23 | } 24 | } 25 | 26 | override public init(frame: CGRect) { 27 | super.init(frame: frame) 28 | 29 | self.isOpaque = false 30 | self.isUserInteractionEnabled = false 31 | } 32 | 33 | required public init?(coder aDecoder: NSCoder) { 34 | super.init(coder: aDecoder) 35 | 36 | } 37 | 38 | override open func draw(_ rect: CGRect) { 39 | 40 | guard let context = UIGraphicsGetCurrentContext() else { 41 | return 42 | } 43 | 44 | let center = CGPoint(x: self.bounds.midX, y: self.bounds.midY) 45 | let radius = self.bounds.midX 46 | 47 | // Fill it: 48 | 49 | context.addArc(center: center, radius: radius - 1.0, startAngle: 0.0, endAngle: 2.0 * .pi, clockwise: true) 50 | self.color.setFill() 51 | context.fillPath() 52 | 53 | // Stroke it (black transucent, inner): 54 | 55 | context.addArc(center: center, radius: radius - 1.0, startAngle: 0.0, endAngle: 2.0 * .pi, clockwise: true) 56 | 57 | context.setStrokeColor(gray: 0.0, alpha: 0.5) 58 | context.setLineWidth(2.0) 59 | context.strokePath() 60 | 61 | // Stroke it (white, outer): 62 | 63 | context.addArc(center: center, radius: radius - 2.0, startAngle: 0.0, endAngle: 2.0 * .pi, clockwise: true) 64 | 65 | context.setStrokeColor(gray: 1.0, alpha: 1.0) 66 | context.setLineWidth(2.0) 67 | context.strokePath() 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /HueKit/View/ColorSquarePicker.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ColorSquarePicker.swift 3 | // HueKit 4 | // 5 | // Created by Louis D'hauwe on 30/07/2017. 6 | // Copyright © 2017 Silver Fox. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | @IBDesignable 13 | open class ColorSquarePicker: UIControl { 14 | 15 | private let contentInsetX: CGFloat = 20 16 | private let contentInsetY: CGFloat = 20 17 | 18 | private let indicatorSizeInactive: CGFloat = 24 19 | private let indicatorSizeActive: CGFloat = 40 20 | 21 | private lazy var colorSquareView: ColorSquareView = { 22 | return ColorSquareView() 23 | }() 24 | 25 | open lazy var indicator: ColorIndicatorView = { 26 | 27 | let size = CGSize(width: self.indicatorSizeInactive, height: self.indicatorSizeInactive) 28 | let indicatorRect = CGRect(origin: .zero, size: size) 29 | 30 | return ColorIndicatorView(frame: indicatorRect) 31 | }() 32 | 33 | @IBInspectable 34 | public var hue: CGFloat = 0.0 { 35 | didSet { 36 | if oldValue != hue { 37 | self.setIndicatorColor() 38 | } 39 | } 40 | } 41 | 42 | @IBInspectable 43 | public var value: CGPoint = .zero { 44 | didSet { 45 | if oldValue != value { 46 | 47 | self.sendActions(for: .valueChanged) 48 | self.setNeedsLayout() 49 | } 50 | } 51 | } 52 | 53 | public var color: UIColor { 54 | return UIColor(hue: hue, saturation: value.x, brightness: value.y, alpha: 1.0) 55 | } 56 | 57 | private func setIndicatorColor() { 58 | 59 | colorSquareView.hue = hue 60 | indicator.color = color 61 | } 62 | 63 | open override func layoutSubviews() { 64 | 65 | if colorSquareView.superview == nil { 66 | 67 | colorSquareView.translatesAutoresizingMaskIntoConstraints = false 68 | self.addSubview(colorSquareView) 69 | 70 | colorSquareView.leadingAnchor.constraint(equalTo: self.leadingAnchor, constant: contentInsetX).isActive = true 71 | colorSquareView.trailingAnchor.constraint(equalTo: self.trailingAnchor, constant: -contentInsetX).isActive = true 72 | colorSquareView.topAnchor.constraint(equalTo: self.topAnchor, constant: contentInsetY).isActive = true 73 | colorSquareView.bottomAnchor.constraint(equalTo: self.bottomAnchor, constant: -contentInsetY).isActive = true 74 | 75 | } 76 | 77 | if indicator.superview == nil { 78 | self.addSubview(indicator) 79 | } 80 | 81 | self.setIndicatorColor() 82 | 83 | let indicatorX = contentInsetX + (self.value.x * (self.bounds.size.width - 2 * contentInsetX)) 84 | let indicatorY = self.bounds.size.height - contentInsetY - (self.value.y * (self.bounds.size.height - 2 * contentInsetY)) 85 | 86 | indicator.center = CGPoint(x: indicatorX, y: indicatorY) 87 | } 88 | 89 | // MARK: - Tracking 90 | 91 | private func trackIndicator(with touch: UITouch) { 92 | let bounds = self.bounds 93 | 94 | var touchValue = CGPoint(x: 0, y: 0) 95 | 96 | touchValue.x = (touch.location(in: self).x - contentInsetX) / (bounds.size.width - 2 * contentInsetX) 97 | 98 | touchValue.y = (touch.location(in: self).y - contentInsetY) / (bounds.size.height - 2 * contentInsetY) 99 | 100 | 101 | touchValue.x = touchValue.x.pinned(between: 0, and: 1) 102 | touchValue.y = 1.0 - touchValue.y.pinned(between: 0, and: 1) 103 | 104 | self.value = touchValue 105 | } 106 | 107 | override open func beginTracking(_ touch: UITouch, with event: UIEvent?) -> Bool { 108 | 109 | self.trackIndicator(with: touch) 110 | 111 | growIndicator() 112 | 113 | return true 114 | } 115 | 116 | override open func continueTracking(_ touch: UITouch, with event: UIEvent?) -> Bool { 117 | 118 | self.trackIndicator(with: touch) 119 | 120 | return true 121 | } 122 | 123 | override open func endTracking(_ touch: UITouch?, with event: UIEvent?) { 124 | super.endTracking(touch, with: event) 125 | 126 | shrinkIndicator() 127 | } 128 | 129 | override open func cancelTracking(with event: UIEvent?) { 130 | super.cancelTracking(with: event) 131 | 132 | shrinkIndicator() 133 | } 134 | 135 | private func changeIndicatorSize(to size: CGFloat) { 136 | 137 | let center = self.indicator.center 138 | 139 | let size = CGSize(width: size, height: size) 140 | let indicatorRect = CGRect(origin: .zero, size: size) 141 | 142 | self.indicator.frame = indicatorRect 143 | self.indicator.center = center 144 | 145 | } 146 | 147 | private func growIndicator() { 148 | 149 | UIView.animate(withDuration: 0.15, delay: 0.0, options: [.curveEaseIn], animations: { 150 | 151 | self.changeIndicatorSize(to: self.indicatorSizeActive) 152 | 153 | }) { (finished) in 154 | 155 | } 156 | 157 | } 158 | 159 | private func shrinkIndicator() { 160 | 161 | UIView.animate(withDuration: 0.15, delay: 0.0, options: [.curveEaseOut], animations: { 162 | 163 | self.changeIndicatorSize(to: self.indicatorSizeInactive) 164 | self.indicator.setNeedsDisplay() 165 | 166 | }) { (finished) in 167 | 168 | self.indicator.setNeedsDisplay() 169 | 170 | } 171 | 172 | } 173 | 174 | } 175 | -------------------------------------------------------------------------------- /HueKit/View/ColorSquareView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ColorSquareView.swift 3 | // HueKit 4 | // 5 | // Created by Louis D'hauwe on 25/07/2017. 6 | // Copyright © 2017 Silver Fox. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @IBDesignable 12 | open class ColorSquareView: UIImageView { 13 | 14 | private var drawnHue: CGFloat = 0.0 15 | 16 | @IBInspectable 17 | open var hue: CGFloat = 0.0 { 18 | didSet { 19 | 20 | if self.image != nil && abs(drawnHue - hue) <= 1e-10 { 21 | return 22 | } 23 | 24 | let cgImage = HSBGen.createSaturationBrightnessSquareContentImageWithHue(hue: self.hue * 360.0) 25 | 26 | if let cgImage = cgImage { 27 | self.image = UIImage(cgImage: cgImage) 28 | } else { 29 | assertionFailure("Expected CGImage") 30 | } 31 | 32 | drawnHue = hue 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /HueKit/View/SourceColorView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SourceColorView.swift 3 | // HueKit 4 | // 5 | // Created by Louis D'hauwe on 30/07/2017. 6 | // Copyright © 2017 Silver Fox. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import UIKit 11 | 12 | @IBDesignable 13 | open class SourceColorView: UIControl { 14 | 15 | @IBInspectable 16 | open var isTrackingInside: Bool = false { 17 | didSet { 18 | if oldValue != isTrackingInside { 19 | self.setNeedsDisplay() 20 | } 21 | } 22 | } 23 | 24 | @IBInspectable 25 | open var dontShrinkWhenPressed: Bool = false { 26 | didSet { 27 | if oldValue != dontShrinkWhenPressed { 28 | self.setNeedsDisplay() 29 | } 30 | } 31 | } 32 | 33 | open override func draw(_ rect: CGRect) { 34 | super.draw(rect) 35 | 36 | guard isEnabled && isTrackingInside && !dontShrinkWhenPressed else { 37 | return 38 | } 39 | 40 | guard let context = UIGraphicsGetCurrentContext() else { 41 | return 42 | } 43 | 44 | let bounds = self.bounds 45 | 46 | UIColor.white.set() 47 | context.stroke(bounds.insetBy(dx: 1, dy: 1), width: 2) 48 | 49 | UIColor.black.set() 50 | UIRectFrame(bounds.insetBy(dx: 2, dy: 2)) 51 | } 52 | 53 | // MARK: - UIControl overrides 54 | 55 | open override func beginTracking(_ touch: UITouch, with event: UIEvent?) -> Bool { 56 | 57 | guard self.isEnabled else { 58 | return false 59 | } 60 | 61 | self.isTrackingInside = true 62 | 63 | return super.beginTracking(touch, with: event) 64 | } 65 | 66 | open override func continueTracking(_ touch: UITouch, with event: UIEvent?) -> Bool { 67 | 68 | let isTrackingInside = self.bounds.contains(touch.location(in: self)) 69 | 70 | self.isTrackingInside = isTrackingInside 71 | 72 | return super.continueTracking(touch, with: event) 73 | } 74 | 75 | open override func endTracking(_ touch: UITouch?, with event: UIEvent?) { 76 | 77 | self.isTrackingInside = false 78 | 79 | super.endTracking(touch, with: event) 80 | } 81 | 82 | open override func cancelTracking(with event: UIEvent?) { 83 | 84 | self.isTrackingInside = false 85 | 86 | super.cancelTracking(with: event) 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Louis D'hauwe 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 |

2 | HueKit for iOS 3 |

4 | 5 |

6 | Build Status 7 |
8 | Swift 9 | Pod Version 10 | Carthage Compatible 11 | Platform: iOS 12 |
13 | Twitter 14 | Donate via PayPal 15 |

16 | 17 |

18 | HueKit for iOS 19 |

20 | 21 | 22 | ## About 23 | HueKit is a UI framework for iOS that provides components and utilities for building color pickers. Since each app may want a custom color picker, the design of this framework is geared towards reusability and allows for great customization. 24 | 25 | ### Components 26 | All components are marked `open`, so they can be subclassed. Also, all components are marked `@IBDesignable`, so they can be previewed in Interface Builder. Components that provide user interaction are subclassed from `UIControl`, you can observe a change in value by using `@IBAction`. 27 | 28 | #### ColorBarPicker 29 | ![](readme-resources/components/ColorBarPicker.png) 30 | 31 | #### ColorBarView 32 | ![](readme-resources/components/ColorBarView.png) 33 | 34 | #### ColorIndicatorView 35 | ![](readme-resources/components/ColorIndicatorView.png) 36 | 37 | #### ColorSquarePicker 38 | ![](readme-resources/components/ColorSquarePicker.png) 39 | 40 | #### ColorSquareView 41 | ![](readme-resources/components/ColorSquareView.png) 42 | 43 | #### SourceColorView 44 | ![](readme-resources/components/SourceColorView.png) 45 | 46 | 47 | ## Installation 48 | 49 | ### [CocoaPods](http://cocoapods.org) 50 | 51 | To install, add the following line to your ```Podfile```: 52 | 53 | ```ruby 54 | pod 'HueKit', '~> 1.0' 55 | ``` 56 | 57 | ### [Carthage](https://github.com/Carthage/Carthage) 58 | To install, add the following line to your ```Cartfile```: 59 | 60 | ```ruby 61 | github "louisdh/huekit" ~> 1.0 62 | ``` 63 | Run ```carthage update``` to build the framework and drag the built ```HueKit.framework``` into your Xcode project. 64 | 65 | 66 | 67 | ## Requirements 68 | 69 | * iOS 10.0+ 70 | * Xcode 9.3+ 71 | 72 | ## Todo 73 | 74 | - [ ] Add tests 75 | - [ ] Add documentation 76 | 77 | ## License 78 | 79 | This project is available under the MIT license. See the LICENSE file for more info. 80 | -------------------------------------------------------------------------------- /readme-resources/components/ColorBarPicker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/louisdh/huekit/c4af0e7abe7c994e719efe934b55f43a1a811eb0/readme-resources/components/ColorBarPicker.png -------------------------------------------------------------------------------- /readme-resources/components/ColorBarView.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/louisdh/huekit/c4af0e7abe7c994e719efe934b55f43a1a811eb0/readme-resources/components/ColorBarView.png -------------------------------------------------------------------------------- /readme-resources/components/ColorIndicatorView.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/louisdh/huekit/c4af0e7abe7c994e719efe934b55f43a1a811eb0/readme-resources/components/ColorIndicatorView.png -------------------------------------------------------------------------------- /readme-resources/components/ColorSquarePicker.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/louisdh/huekit/c4af0e7abe7c994e719efe934b55f43a1a811eb0/readme-resources/components/ColorSquarePicker.png -------------------------------------------------------------------------------- /readme-resources/components/ColorSquareView.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/louisdh/huekit/c4af0e7abe7c994e719efe934b55f43a1a811eb0/readme-resources/components/ColorSquareView.png -------------------------------------------------------------------------------- /readme-resources/components/SourceColorView.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/louisdh/huekit/c4af0e7abe7c994e719efe934b55f43a1a811eb0/readme-resources/components/SourceColorView.png -------------------------------------------------------------------------------- /readme-resources/example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/louisdh/huekit/c4af0e7abe7c994e719efe934b55f43a1a811eb0/readme-resources/example.gif -------------------------------------------------------------------------------- /readme-resources/hero@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/louisdh/huekit/c4af0e7abe7c994e719efe934b55f43a1a811eb0/readme-resources/hero@2x.png --------------------------------------------------------------------------------