├── .gitignore ├── LICENSE ├── README.md ├── TouchGradientPicker.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcshareddata │ └── xcschemes │ └── TouchGradientPicker.xcscheme ├── TouchGradientPicker.xcworkspace └── contents.xcworkspacedata ├── TouchGradientPicker ├── CenterColorGradient.swift ├── CenterColorGradientBuilder.swift ├── GradientBuilder.swift ├── GradientType.swift ├── GradientView.swift ├── Info.plist ├── Pan.swift ├── TouchGradientPicker.h ├── TouchGradientPicker.swift └── UIColorExtensions.swift ├── TouchGradientPickerDemo ├── TouchGradientPickerDemo.xcodeproj │ └── project.pbxproj ├── TouchGradientPickerDemo │ ├── AppDelegate.swift │ ├── Base.lproj │ │ ├── LaunchScreen.xib │ │ └── Main.storyboard │ ├── Images.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Info.plist │ └── ViewController.swift └── TouchGradientPickerDemoTests │ ├── Info.plist │ └── TouchGradientPickerDemoTests.swift └── TouchGradientPickerTests ├── Info.plist └── TouchGradientPickerTests.swift /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | # Pods/ 27 | 28 | # Carthage 29 | # 30 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 31 | # Carthage/Checkouts 32 | 33 | Carthage/Build 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Mike Mertsock 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 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TouchGradientPicker [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) 2 | 3 | TouchGradientPicker is a UIKit framework for displaying and editing color gradients. 4 | 5 | - Render gradients with a simple UIView subclass and a couple lines of code 6 | - Build a customized control for editing gradients 7 | - Gradient picker uses no sliders or buttons: all input is gesture-based for an analog, organic feel; you can build a beautiful full-screen picker 8 | - 100% Swift, iOS 8 required 9 | - Abstract API, extensible via subclassing and functional programming 10 | - Flexible layout options: gradient display and editor input are separate views that can be laid however you please, in IB or programmatically 11 | 12 | TouchGradientPicker was developed for and featured in [Dayly Calendar][]. See the [app preview video][video], at about 18 seconds in, for a quick demo. 13 | 14 | You can also bookmark/favorite TouchGradientPicker on [CocoaControls][]. 15 | 16 | ## Show me some code! 17 | 18 | See the [demo code][] for a concrete, runnable example of TouchGradientPicker usage and gradient builder setup. The code is annotated with comments. You can also continue reading a high level overview of the code below. 19 | 20 | ## GradientView: display color gradients in a simple UIView 21 | 22 | A simple UIView subclass that draws a gradient background, by setting the value of the `gradient` property. Drop this onto your storyboard scene in Xcode with whatever layout you want. 23 | 24 | ## GradientType: abstract value types that model gradients 25 | 26 | The `GradientType` protocol defines a list of color-position pairs. Each color is associated with a float value between 0 and 1. These values place the color points along the length of the gradient, and the color at each point along the gradient is determined by interpolating the adjacent colors. See [`CGGradient` reference][CGGradient] for more info. 27 | 28 | Implementations of GradientType provide various ways to construct gradients. The single implementation currently provided, `CenterColorGradient`, describes a gradient by defining the color to display at the “center” of the gradient, and the amount by which to shift various components of that color at each endpoint of the gradient. 29 | 30 | You can build your own implementation of GradientType as well. 31 | 32 | ## TouchGradientPicker 33 | 34 | This is a lightweight UIView that translates gesture-based inputs into transformations on a GradientType, which are applied to a corresponding GradientView. To use this control, add both a GradientView and TouchGradientPicker to your storyboard, connect the outlet from the picker to the GradientView, and you'll likely want some outlets connecting your view controller to these views. 35 | 36 | In `viewDidLoad` or another appropriate place, you need to configure the picker by setting the `gradientBuilder` property. Classes conforming to the `GradientBuilder` protocol act as a delegate for the picker, producing new GradientTypes based on user gestures. 37 | 38 | Currently the single available builder is `CenterColorGradientBuilder`, which produces `CenterColorGradient` objects. Create an instance of this class and initialize with a default gradient value. Assign this to the `gradientBuilder` property of the picker. 39 | 40 | ### CenterColorGradientBuilder 41 | 42 | In addition to creating an object of this class and assigning it to the picker object, you need to configure how it reacts to the user's pan gestures. You assign one or more properties on the builder object, such as `hueVariance` or `centerColor.hue`. You assign blocks that take the current value and `Pan` gesture data as input, and return a new hue/color/etc. value. For example, you may wish to have horizontal pan gestures result in a positive/negative shift in the average hue of the gradient. 43 | 44 | [Dayly Calendar]: http://www.esker-apps.com/dayly/ 45 | [video]: http://www.esker-apps.com/dayly/demo/ 46 | [CocoaControls]: https://www.cocoacontrols.com/controls/touchgradientpicker 47 | [CGGradient]: https://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CGGradient/index.html 48 | [demo code]: https://github.com/mmertsock/TouchGradientPicker/blob/master/TouchGradientPickerDemo/TouchGradientPickerDemo/ViewController.swift 49 | -------------------------------------------------------------------------------- /TouchGradientPicker.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 2783749A1B86BA8F00705ED2 /* Pan.swift in Sources */ = {isa = PBXBuildFile; fileRef = 278374991B86BA8F00705ED2 /* Pan.swift */; }; 11 | 2783749C1B86BAC200705ED2 /* GradientBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2783749B1B86BAC200705ED2 /* GradientBuilder.swift */; }; 12 | 2786BB0A1B855CBF00AEAB41 /* TouchGradientPicker.h in Headers */ = {isa = PBXBuildFile; fileRef = 2786BB091B855CBF00AEAB41 /* TouchGradientPicker.h */; settings = {ATTRIBUTES = (Public, ); }; }; 13 | 2786BB101B855CBF00AEAB41 /* TouchGradientPicker.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2786BB041B855CBF00AEAB41 /* TouchGradientPicker.framework */; }; 14 | 2786BB171B855CBF00AEAB41 /* TouchGradientPickerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2786BB161B855CBF00AEAB41 /* TouchGradientPickerTests.swift */; }; 15 | 2786BB211B855DFE00AEAB41 /* GradientView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2786BB201B855DFE00AEAB41 /* GradientView.swift */; }; 16 | 2786BB231B85655A00AEAB41 /* GradientType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2786BB221B85655A00AEAB41 /* GradientType.swift */; }; 17 | 2786BB251B85662600AEAB41 /* CenterColorGradient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2786BB241B85662600AEAB41 /* CenterColorGradient.swift */; }; 18 | 2786BB8C1B856CBE00AEAB41 /* UIColorExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2786BB8B1B856CBE00AEAB41 /* UIColorExtensions.swift */; }; 19 | 2786BB8E1B856E8900AEAB41 /* CenterColorGradientBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2786BB8D1B856E8900AEAB41 /* CenterColorGradientBuilder.swift */; }; 20 | 27890ADA1B8572CB000E8597 /* TouchGradientPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27890AD91B8572CB000E8597 /* TouchGradientPicker.swift */; }; 21 | /* End PBXBuildFile section */ 22 | 23 | /* Begin PBXContainerItemProxy section */ 24 | 2786BB111B855CBF00AEAB41 /* PBXContainerItemProxy */ = { 25 | isa = PBXContainerItemProxy; 26 | containerPortal = 2786BAFB1B855CBF00AEAB41 /* Project object */; 27 | proxyType = 1; 28 | remoteGlobalIDString = 2786BB031B855CBF00AEAB41; 29 | remoteInfo = TouchGradientPicker; 30 | }; 31 | /* End PBXContainerItemProxy section */ 32 | 33 | /* Begin PBXFileReference section */ 34 | 278374991B86BA8F00705ED2 /* Pan.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Pan.swift; sourceTree = ""; }; 35 | 2783749B1B86BAC200705ED2 /* GradientBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GradientBuilder.swift; sourceTree = ""; }; 36 | 2786BB041B855CBF00AEAB41 /* TouchGradientPicker.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = TouchGradientPicker.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 37 | 2786BB081B855CBF00AEAB41 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 38 | 2786BB091B855CBF00AEAB41 /* TouchGradientPicker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TouchGradientPicker.h; sourceTree = ""; }; 39 | 2786BB0F1B855CBF00AEAB41 /* TouchGradientPickerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TouchGradientPickerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 40 | 2786BB151B855CBF00AEAB41 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 41 | 2786BB161B855CBF00AEAB41 /* TouchGradientPickerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TouchGradientPickerTests.swift; sourceTree = ""; }; 42 | 2786BB201B855DFE00AEAB41 /* GradientView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GradientView.swift; sourceTree = ""; }; 43 | 2786BB221B85655A00AEAB41 /* GradientType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GradientType.swift; sourceTree = ""; }; 44 | 2786BB241B85662600AEAB41 /* CenterColorGradient.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CenterColorGradient.swift; sourceTree = ""; }; 45 | 2786BB8B1B856CBE00AEAB41 /* UIColorExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIColorExtensions.swift; sourceTree = ""; }; 46 | 2786BB8D1B856E8900AEAB41 /* CenterColorGradientBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CenterColorGradientBuilder.swift; sourceTree = ""; }; 47 | 27890AD91B8572CB000E8597 /* TouchGradientPicker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TouchGradientPicker.swift; sourceTree = ""; }; 48 | /* End PBXFileReference section */ 49 | 50 | /* Begin PBXFrameworksBuildPhase section */ 51 | 2786BB001B855CBF00AEAB41 /* Frameworks */ = { 52 | isa = PBXFrameworksBuildPhase; 53 | buildActionMask = 2147483647; 54 | files = ( 55 | ); 56 | runOnlyForDeploymentPostprocessing = 0; 57 | }; 58 | 2786BB0C1B855CBF00AEAB41 /* Frameworks */ = { 59 | isa = PBXFrameworksBuildPhase; 60 | buildActionMask = 2147483647; 61 | files = ( 62 | 2786BB101B855CBF00AEAB41 /* TouchGradientPicker.framework in Frameworks */, 63 | ); 64 | runOnlyForDeploymentPostprocessing = 0; 65 | }; 66 | /* End PBXFrameworksBuildPhase section */ 67 | 68 | /* Begin PBXGroup section */ 69 | 2786BAFA1B855CBF00AEAB41 = { 70 | isa = PBXGroup; 71 | children = ( 72 | 2786BB061B855CBF00AEAB41 /* TouchGradientPicker */, 73 | 2786BB131B855CBF00AEAB41 /* TouchGradientPickerTests */, 74 | 2786BB051B855CBF00AEAB41 /* Products */, 75 | ); 76 | sourceTree = ""; 77 | }; 78 | 2786BB051B855CBF00AEAB41 /* Products */ = { 79 | isa = PBXGroup; 80 | children = ( 81 | 2786BB041B855CBF00AEAB41 /* TouchGradientPicker.framework */, 82 | 2786BB0F1B855CBF00AEAB41 /* TouchGradientPickerTests.xctest */, 83 | ); 84 | name = Products; 85 | sourceTree = ""; 86 | }; 87 | 2786BB061B855CBF00AEAB41 /* TouchGradientPicker */ = { 88 | isa = PBXGroup; 89 | children = ( 90 | 2786BB241B85662600AEAB41 /* CenterColorGradient.swift */, 91 | 2786BB221B85655A00AEAB41 /* GradientType.swift */, 92 | 2786BB201B855DFE00AEAB41 /* GradientView.swift */, 93 | 2786BB071B855CBF00AEAB41 /* Supporting Files */, 94 | 2786BB091B855CBF00AEAB41 /* TouchGradientPicker.h */, 95 | 2786BB8B1B856CBE00AEAB41 /* UIColorExtensions.swift */, 96 | 2786BB8D1B856E8900AEAB41 /* CenterColorGradientBuilder.swift */, 97 | 27890AD91B8572CB000E8597 /* TouchGradientPicker.swift */, 98 | 278374991B86BA8F00705ED2 /* Pan.swift */, 99 | 2783749B1B86BAC200705ED2 /* GradientBuilder.swift */, 100 | ); 101 | path = TouchGradientPicker; 102 | sourceTree = ""; 103 | }; 104 | 2786BB071B855CBF00AEAB41 /* Supporting Files */ = { 105 | isa = PBXGroup; 106 | children = ( 107 | 2786BB081B855CBF00AEAB41 /* Info.plist */, 108 | ); 109 | name = "Supporting Files"; 110 | sourceTree = ""; 111 | }; 112 | 2786BB131B855CBF00AEAB41 /* TouchGradientPickerTests */ = { 113 | isa = PBXGroup; 114 | children = ( 115 | 2786BB161B855CBF00AEAB41 /* TouchGradientPickerTests.swift */, 116 | 2786BB141B855CBF00AEAB41 /* Supporting Files */, 117 | ); 118 | path = TouchGradientPickerTests; 119 | sourceTree = ""; 120 | }; 121 | 2786BB141B855CBF00AEAB41 /* Supporting Files */ = { 122 | isa = PBXGroup; 123 | children = ( 124 | 2786BB151B855CBF00AEAB41 /* Info.plist */, 125 | ); 126 | name = "Supporting Files"; 127 | sourceTree = ""; 128 | }; 129 | /* End PBXGroup section */ 130 | 131 | /* Begin PBXHeadersBuildPhase section */ 132 | 2786BB011B855CBF00AEAB41 /* Headers */ = { 133 | isa = PBXHeadersBuildPhase; 134 | buildActionMask = 2147483647; 135 | files = ( 136 | 2786BB0A1B855CBF00AEAB41 /* TouchGradientPicker.h in Headers */, 137 | ); 138 | runOnlyForDeploymentPostprocessing = 0; 139 | }; 140 | /* End PBXHeadersBuildPhase section */ 141 | 142 | /* Begin PBXNativeTarget section */ 143 | 2786BB031B855CBF00AEAB41 /* TouchGradientPicker */ = { 144 | isa = PBXNativeTarget; 145 | buildConfigurationList = 2786BB1A1B855CBF00AEAB41 /* Build configuration list for PBXNativeTarget "TouchGradientPicker" */; 146 | buildPhases = ( 147 | 2786BAFF1B855CBF00AEAB41 /* Sources */, 148 | 2786BB001B855CBF00AEAB41 /* Frameworks */, 149 | 2786BB011B855CBF00AEAB41 /* Headers */, 150 | 2786BB021B855CBF00AEAB41 /* Resources */, 151 | ); 152 | buildRules = ( 153 | ); 154 | dependencies = ( 155 | ); 156 | name = TouchGradientPicker; 157 | productName = TouchGradientPicker; 158 | productReference = 2786BB041B855CBF00AEAB41 /* TouchGradientPicker.framework */; 159 | productType = "com.apple.product-type.framework"; 160 | }; 161 | 2786BB0E1B855CBF00AEAB41 /* TouchGradientPickerTests */ = { 162 | isa = PBXNativeTarget; 163 | buildConfigurationList = 2786BB1D1B855CBF00AEAB41 /* Build configuration list for PBXNativeTarget "TouchGradientPickerTests" */; 164 | buildPhases = ( 165 | 2786BB0B1B855CBF00AEAB41 /* Sources */, 166 | 2786BB0C1B855CBF00AEAB41 /* Frameworks */, 167 | 2786BB0D1B855CBF00AEAB41 /* Resources */, 168 | ); 169 | buildRules = ( 170 | ); 171 | dependencies = ( 172 | 2786BB121B855CBF00AEAB41 /* PBXTargetDependency */, 173 | ); 174 | name = TouchGradientPickerTests; 175 | productName = TouchGradientPickerTests; 176 | productReference = 2786BB0F1B855CBF00AEAB41 /* TouchGradientPickerTests.xctest */; 177 | productType = "com.apple.product-type.bundle.unit-test"; 178 | }; 179 | /* End PBXNativeTarget section */ 180 | 181 | /* Begin PBXProject section */ 182 | 2786BAFB1B855CBF00AEAB41 /* Project object */ = { 183 | isa = PBXProject; 184 | attributes = { 185 | LastSwiftMigration = 0700; 186 | LastSwiftUpdateCheck = 0700; 187 | LastUpgradeCheck = 0700; 188 | ORGANIZATIONNAME = "Esker Apps"; 189 | TargetAttributes = { 190 | 2786BB031B855CBF00AEAB41 = { 191 | CreatedOnToolsVersion = 6.4; 192 | }; 193 | 2786BB0E1B855CBF00AEAB41 = { 194 | CreatedOnToolsVersion = 6.4; 195 | }; 196 | }; 197 | }; 198 | buildConfigurationList = 2786BAFE1B855CBF00AEAB41 /* Build configuration list for PBXProject "TouchGradientPicker" */; 199 | compatibilityVersion = "Xcode 3.2"; 200 | developmentRegion = English; 201 | hasScannedForEncodings = 0; 202 | knownRegions = ( 203 | en, 204 | ); 205 | mainGroup = 2786BAFA1B855CBF00AEAB41; 206 | productRefGroup = 2786BB051B855CBF00AEAB41 /* Products */; 207 | projectDirPath = ""; 208 | projectRoot = ""; 209 | targets = ( 210 | 2786BB031B855CBF00AEAB41 /* TouchGradientPicker */, 211 | 2786BB0E1B855CBF00AEAB41 /* TouchGradientPickerTests */, 212 | ); 213 | }; 214 | /* End PBXProject section */ 215 | 216 | /* Begin PBXResourcesBuildPhase section */ 217 | 2786BB021B855CBF00AEAB41 /* Resources */ = { 218 | isa = PBXResourcesBuildPhase; 219 | buildActionMask = 2147483647; 220 | files = ( 221 | ); 222 | runOnlyForDeploymentPostprocessing = 0; 223 | }; 224 | 2786BB0D1B855CBF00AEAB41 /* Resources */ = { 225 | isa = PBXResourcesBuildPhase; 226 | buildActionMask = 2147483647; 227 | files = ( 228 | ); 229 | runOnlyForDeploymentPostprocessing = 0; 230 | }; 231 | /* End PBXResourcesBuildPhase section */ 232 | 233 | /* Begin PBXSourcesBuildPhase section */ 234 | 2786BAFF1B855CBF00AEAB41 /* Sources */ = { 235 | isa = PBXSourcesBuildPhase; 236 | buildActionMask = 2147483647; 237 | files = ( 238 | 2786BB251B85662600AEAB41 /* CenterColorGradient.swift in Sources */, 239 | 2786BB211B855DFE00AEAB41 /* GradientView.swift in Sources */, 240 | 2786BB231B85655A00AEAB41 /* GradientType.swift in Sources */, 241 | 2783749A1B86BA8F00705ED2 /* Pan.swift in Sources */, 242 | 27890ADA1B8572CB000E8597 /* TouchGradientPicker.swift in Sources */, 243 | 2783749C1B86BAC200705ED2 /* GradientBuilder.swift in Sources */, 244 | 2786BB8C1B856CBE00AEAB41 /* UIColorExtensions.swift in Sources */, 245 | 2786BB8E1B856E8900AEAB41 /* CenterColorGradientBuilder.swift in Sources */, 246 | ); 247 | runOnlyForDeploymentPostprocessing = 0; 248 | }; 249 | 2786BB0B1B855CBF00AEAB41 /* Sources */ = { 250 | isa = PBXSourcesBuildPhase; 251 | buildActionMask = 2147483647; 252 | files = ( 253 | 2786BB171B855CBF00AEAB41 /* TouchGradientPickerTests.swift in Sources */, 254 | ); 255 | runOnlyForDeploymentPostprocessing = 0; 256 | }; 257 | /* End PBXSourcesBuildPhase section */ 258 | 259 | /* Begin PBXTargetDependency section */ 260 | 2786BB121B855CBF00AEAB41 /* PBXTargetDependency */ = { 261 | isa = PBXTargetDependency; 262 | target = 2786BB031B855CBF00AEAB41 /* TouchGradientPicker */; 263 | targetProxy = 2786BB111B855CBF00AEAB41 /* PBXContainerItemProxy */; 264 | }; 265 | /* End PBXTargetDependency section */ 266 | 267 | /* Begin XCBuildConfiguration section */ 268 | 2786BB181B855CBF00AEAB41 /* Debug */ = { 269 | isa = XCBuildConfiguration; 270 | buildSettings = { 271 | ALWAYS_SEARCH_USER_PATHS = NO; 272 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 273 | CLANG_CXX_LIBRARY = "libc++"; 274 | CLANG_ENABLE_MODULES = YES; 275 | CLANG_ENABLE_OBJC_ARC = YES; 276 | CLANG_WARN_BOOL_CONVERSION = YES; 277 | CLANG_WARN_CONSTANT_CONVERSION = YES; 278 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 279 | CLANG_WARN_EMPTY_BODY = YES; 280 | CLANG_WARN_ENUM_CONVERSION = YES; 281 | CLANG_WARN_INT_CONVERSION = YES; 282 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 283 | CLANG_WARN_UNREACHABLE_CODE = YES; 284 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 285 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 286 | COPY_PHASE_STRIP = NO; 287 | CURRENT_PROJECT_VERSION = 1; 288 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 289 | ENABLE_STRICT_OBJC_MSGSEND = YES; 290 | ENABLE_TESTABILITY = YES; 291 | GCC_C_LANGUAGE_STANDARD = gnu99; 292 | GCC_DYNAMIC_NO_PIC = NO; 293 | GCC_NO_COMMON_BLOCKS = YES; 294 | GCC_OPTIMIZATION_LEVEL = 0; 295 | GCC_PREPROCESSOR_DEFINITIONS = ( 296 | "DEBUG=1", 297 | "$(inherited)", 298 | ); 299 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 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 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 307 | MTL_ENABLE_DEBUG_INFO = YES; 308 | ONLY_ACTIVE_ARCH = YES; 309 | SDKROOT = iphoneos; 310 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 311 | TARGETED_DEVICE_FAMILY = "1,2"; 312 | VERSIONING_SYSTEM = "apple-generic"; 313 | VERSION_INFO_PREFIX = ""; 314 | }; 315 | name = Debug; 316 | }; 317 | 2786BB191B855CBF00AEAB41 /* Release */ = { 318 | isa = XCBuildConfiguration; 319 | buildSettings = { 320 | ALWAYS_SEARCH_USER_PATHS = NO; 321 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 322 | CLANG_CXX_LIBRARY = "libc++"; 323 | CLANG_ENABLE_MODULES = YES; 324 | CLANG_ENABLE_OBJC_ARC = YES; 325 | CLANG_WARN_BOOL_CONVERSION = YES; 326 | CLANG_WARN_CONSTANT_CONVERSION = YES; 327 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 328 | CLANG_WARN_EMPTY_BODY = YES; 329 | CLANG_WARN_ENUM_CONVERSION = YES; 330 | CLANG_WARN_INT_CONVERSION = YES; 331 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 332 | CLANG_WARN_UNREACHABLE_CODE = YES; 333 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 334 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 335 | COPY_PHASE_STRIP = NO; 336 | CURRENT_PROJECT_VERSION = 1; 337 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 338 | ENABLE_NS_ASSERTIONS = NO; 339 | ENABLE_STRICT_OBJC_MSGSEND = YES; 340 | GCC_C_LANGUAGE_STANDARD = gnu99; 341 | GCC_NO_COMMON_BLOCKS = YES; 342 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 343 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 344 | GCC_WARN_UNDECLARED_SELECTOR = YES; 345 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 346 | GCC_WARN_UNUSED_FUNCTION = YES; 347 | GCC_WARN_UNUSED_VARIABLE = YES; 348 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 349 | MTL_ENABLE_DEBUG_INFO = NO; 350 | SDKROOT = iphoneos; 351 | TARGETED_DEVICE_FAMILY = "1,2"; 352 | VALIDATE_PRODUCT = YES; 353 | VERSIONING_SYSTEM = "apple-generic"; 354 | VERSION_INFO_PREFIX = ""; 355 | }; 356 | name = Release; 357 | }; 358 | 2786BB1B1B855CBF00AEAB41 /* Debug */ = { 359 | isa = XCBuildConfiguration; 360 | buildSettings = { 361 | CLANG_ENABLE_MODULES = YES; 362 | DEFINES_MODULE = YES; 363 | DYLIB_COMPATIBILITY_VERSION = 1; 364 | DYLIB_CURRENT_VERSION = 1; 365 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 366 | INFOPLIST_FILE = TouchGradientPicker/Info.plist; 367 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 368 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 369 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 370 | PRODUCT_BUNDLE_IDENTIFIER = "com.esker-apps.$(PRODUCT_NAME:rfc1034identifier)"; 371 | PRODUCT_NAME = "$(TARGET_NAME)"; 372 | SKIP_INSTALL = YES; 373 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 374 | }; 375 | name = Debug; 376 | }; 377 | 2786BB1C1B855CBF00AEAB41 /* Release */ = { 378 | isa = XCBuildConfiguration; 379 | buildSettings = { 380 | CLANG_ENABLE_MODULES = YES; 381 | DEFINES_MODULE = YES; 382 | DYLIB_COMPATIBILITY_VERSION = 1; 383 | DYLIB_CURRENT_VERSION = 1; 384 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 385 | INFOPLIST_FILE = TouchGradientPicker/Info.plist; 386 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 387 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 388 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 389 | PRODUCT_BUNDLE_IDENTIFIER = "com.esker-apps.$(PRODUCT_NAME:rfc1034identifier)"; 390 | PRODUCT_NAME = "$(TARGET_NAME)"; 391 | SKIP_INSTALL = YES; 392 | }; 393 | name = Release; 394 | }; 395 | 2786BB1E1B855CBF00AEAB41 /* Debug */ = { 396 | isa = XCBuildConfiguration; 397 | buildSettings = { 398 | FRAMEWORK_SEARCH_PATHS = ( 399 | "$(SDKROOT)/Developer/Library/Frameworks", 400 | "$(inherited)", 401 | ); 402 | GCC_PREPROCESSOR_DEFINITIONS = ( 403 | "DEBUG=1", 404 | "$(inherited)", 405 | ); 406 | INFOPLIST_FILE = TouchGradientPickerTests/Info.plist; 407 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 408 | PRODUCT_BUNDLE_IDENTIFIER = "com.esker-apps.$(PRODUCT_NAME:rfc1034identifier)"; 409 | PRODUCT_NAME = "$(TARGET_NAME)"; 410 | }; 411 | name = Debug; 412 | }; 413 | 2786BB1F1B855CBF00AEAB41 /* Release */ = { 414 | isa = XCBuildConfiguration; 415 | buildSettings = { 416 | FRAMEWORK_SEARCH_PATHS = ( 417 | "$(SDKROOT)/Developer/Library/Frameworks", 418 | "$(inherited)", 419 | ); 420 | INFOPLIST_FILE = TouchGradientPickerTests/Info.plist; 421 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 422 | PRODUCT_BUNDLE_IDENTIFIER = "com.esker-apps.$(PRODUCT_NAME:rfc1034identifier)"; 423 | PRODUCT_NAME = "$(TARGET_NAME)"; 424 | }; 425 | name = Release; 426 | }; 427 | /* End XCBuildConfiguration section */ 428 | 429 | /* Begin XCConfigurationList section */ 430 | 2786BAFE1B855CBF00AEAB41 /* Build configuration list for PBXProject "TouchGradientPicker" */ = { 431 | isa = XCConfigurationList; 432 | buildConfigurations = ( 433 | 2786BB181B855CBF00AEAB41 /* Debug */, 434 | 2786BB191B855CBF00AEAB41 /* Release */, 435 | ); 436 | defaultConfigurationIsVisible = 0; 437 | defaultConfigurationName = Release; 438 | }; 439 | 2786BB1A1B855CBF00AEAB41 /* Build configuration list for PBXNativeTarget "TouchGradientPicker" */ = { 440 | isa = XCConfigurationList; 441 | buildConfigurations = ( 442 | 2786BB1B1B855CBF00AEAB41 /* Debug */, 443 | 2786BB1C1B855CBF00AEAB41 /* Release */, 444 | ); 445 | defaultConfigurationIsVisible = 0; 446 | defaultConfigurationName = Release; 447 | }; 448 | 2786BB1D1B855CBF00AEAB41 /* Build configuration list for PBXNativeTarget "TouchGradientPickerTests" */ = { 449 | isa = XCConfigurationList; 450 | buildConfigurations = ( 451 | 2786BB1E1B855CBF00AEAB41 /* Debug */, 452 | 2786BB1F1B855CBF00AEAB41 /* Release */, 453 | ); 454 | defaultConfigurationIsVisible = 0; 455 | defaultConfigurationName = Release; 456 | }; 457 | /* End XCConfigurationList section */ 458 | }; 459 | rootObject = 2786BAFB1B855CBF00AEAB41 /* Project object */; 460 | } 461 | -------------------------------------------------------------------------------- /TouchGradientPicker.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /TouchGradientPicker.xcodeproj/xcshareddata/xcschemes/TouchGradientPicker.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 67 | 68 | 78 | 79 | 85 | 86 | 87 | 88 | 89 | 90 | 96 | 97 | 103 | 104 | 105 | 106 | 108 | 109 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /TouchGradientPicker.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /TouchGradientPicker/CenterColorGradient.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CenterColorGradient.swift 3 | // TouchGradientPicker 4 | // 5 | // Created by Mike Mertsock on 8/19/15. 6 | // Copyright (c) 2015 Esker Apps. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public struct CenterColorGradient: GradientType { 12 | 13 | // The color at the "midpoint" of the gradient 14 | public let centerColor: UIColor 15 | 16 | // The amount by which to shift the hue of the centerColor at each 17 | // "endpoint" of the gradient. Negative values permitted 18 | public let hueVariance: CGFloat 19 | 20 | // The amount by which to shift the saturation of the centerColor at 21 | // each "endpoint" of the gradient. Negative values permitted 22 | public let satVariance: CGFloat 23 | 24 | // The amount by which to shift the brightness of the centerColor at 25 | // each "endpoint" of the gradient. Negative values permitted 26 | public let brightnessVariance: CGFloat 27 | 28 | // The amount by which to shift the opacity of the centerColor at 29 | // each "endpoint" of the gradient. Negative values permitted 30 | public let alphaVariance: CGFloat 31 | 32 | public var colorPoints: [(CGFloat, UIColor)] { 33 | get { 34 | return [(0, startColor), (0.5, centerColor), (1, endColor)] 35 | } 36 | } 37 | 38 | public var startColor: UIColor { 39 | return makeColor(-1) 40 | } 41 | 42 | public var endColor: UIColor { 43 | return makeColor(1) 44 | } 45 | 46 | private func makeColor(factor: CGFloat) -> UIColor { 47 | let (h, s, b, a) = centerColor.getHSBAComponents() 48 | return UIColor( 49 | hue: h + factor * hueVariance, 50 | saturation: s + factor * satVariance, 51 | brightness: b + factor * brightnessVariance, 52 | alpha: a + factor * alphaVariance) 53 | } 54 | 55 | // TODO why do we have to manually write this ctor 56 | 57 | public init(centerColor: UIColor, hueVariance: CGFloat, satVariance: CGFloat, brightnessVariance: CGFloat, alphaVariance: CGFloat) { 58 | self.centerColor = centerColor 59 | self.hueVariance = hueVariance 60 | self.satVariance = satVariance 61 | self.brightnessVariance = brightnessVariance 62 | self.alphaVariance = alphaVariance 63 | } 64 | } 65 | 66 | public extension CenterColorGradient { 67 | public init(flatColor: UIColor) { 68 | centerColor = flatColor 69 | hueVariance = 0 70 | satVariance = 0 71 | brightnessVariance = 0 72 | alphaVariance = 0 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /TouchGradientPicker/CenterColorGradientBuilder.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CenterColorGradientBuilder.swift 3 | // TouchGradientPicker 4 | // 5 | // Created by Mike Mertsock on 8/19/15. 6 | // Copyright (c) 2015 Esker Apps. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public class CenterColorGradientBuilder: GradientBuilder { 12 | 13 | public private(set) var currentValue: CenterColorGradient 14 | 15 | public struct CenterColorBuilderParams { 16 | public var hue: ((Pan, CGFloat) -> CGFloat)? 17 | public var saturation: ((Pan, CGFloat) -> CGFloat)? 18 | public var brightness: ((Pan, CGFloat) -> CGFloat)? 19 | public var alpha: ((Pan, CGFloat) -> CGFloat)? 20 | func colorFromPan(pan: Pan, panStartValue: UIColor) -> UIColor { 21 | let (h, s, b, a) = panStartValue.getHSBAComponents() 22 | let newHue = hue?(pan, h) 23 | let newSaturation = saturation?(pan, s) 24 | let newBrightness = brightness?(pan, b) 25 | let newAlpha = alpha?(pan, a) 26 | return UIColor( 27 | hue: newHue ?? h, 28 | saturation: newSaturation ?? s, 29 | brightness: newBrightness ?? b, 30 | alpha: newAlpha ?? a) 31 | } 32 | } 33 | 34 | public var centerColor = CenterColorBuilderParams() 35 | 36 | public var hueVariance: ((Pan, CGFloat) -> CGFloat)? 37 | 38 | public var satVariance: ((Pan, CGFloat) -> CGFloat)? 39 | 40 | public var brightnessVariance: ((Pan, CGFloat) -> CGFloat)? 41 | 42 | public var alphaVariance: ((Pan, CGFloat) -> CGFloat)? 43 | 44 | public init(initialValue: CenterColorGradient) { 45 | currentValue = initialValue 46 | } 47 | 48 | public func gradientFromPan(pan: Pan, panStartValue: GradientType) -> GradientType { 49 | let panStartValue = (panStartValue as? CenterColorGradient) ?? currentValue 50 | let newCenterColor = centerColor.colorFromPan(pan, panStartValue: panStartValue.centerColor) 51 | let newHueVariance = hueVariance?(pan, panStartValue.hueVariance) 52 | let newSatVariance = satVariance?(pan, panStartValue.satVariance) 53 | let newBrightnessVariance = brightnessVariance?(pan, panStartValue.brightnessVariance) 54 | let newAlphaVariance = alphaVariance?(pan, panStartValue.alphaVariance) 55 | currentValue = CenterColorGradient( 56 | centerColor: newCenterColor, 57 | hueVariance: newHueVariance ?? panStartValue.hueVariance, 58 | satVariance: newSatVariance ?? panStartValue.satVariance, 59 | brightnessVariance: newBrightnessVariance ?? panStartValue.brightnessVariance, 60 | alphaVariance: newAlphaVariance ?? panStartValue.alphaVariance) 61 | return currentValue 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /TouchGradientPicker/GradientBuilder.swift: -------------------------------------------------------------------------------- 1 | // 2 | // GradientBuilder.swift 3 | // TouchGradientPicker 4 | // 5 | // Created by Mike Mertsock on 8/20/15. 6 | // Copyright (c) 2015 Esker Apps. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public protocol GradientBuilder { 12 | func gradientFromPan(pan: Pan, panStartValue: GradientType) -> GradientType 13 | } 14 | -------------------------------------------------------------------------------- /TouchGradientPicker/GradientType.swift: -------------------------------------------------------------------------------- 1 | // 2 | // GradientType.swift 3 | // TouchGradientPicker 4 | // 5 | // Created by Mike Mertsock on 8/19/15. 6 | // Copyright (c) 2015 Esker Apps. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public protocol GradientType { 12 | // Defines colors at points along the abstract length 13 | // or radius of a gradient. The float values should be 14 | // between 0 and 1, inclusive. 15 | var colorPoints: [(CGFloat, UIColor)] { get } 16 | } 17 | 18 | public extension UIView { 19 | public func fillWithGradient(gradient: GradientType, context: CGContext!) { 20 | let CGColors = gradient.colorPoints.map { $0.1.CGColor } 21 | let locations = gradient.colorPoints.map { $0.0 } 22 | let gradient = CGGradientCreateWithColors(CGColorSpaceCreateDeviceRGB(), CGColors, locations) 23 | 24 | let bounds = self.bounds 25 | let startPoint = CGPointMake(bounds.midX, bounds.minY) 26 | let endPoint = CGPointMake(bounds.midX, bounds.maxY) 27 | let opts = CGGradientDrawingOptions([CGGradientDrawingOptions.DrawsAfterEndLocation, CGGradientDrawingOptions.DrawsBeforeStartLocation]) 28 | CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, opts) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /TouchGradientPicker/GradientView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // GradientView.swift 3 | // TouchGradientPicker 4 | // 5 | // Created by Mike Mertsock on 8/19/15. 6 | // Copyright (c) 2015 Esker Apps. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public class GradientView: UIView { 12 | public var gradient: GradientType = CenterColorGradient(flatColor: UIColor.blackColor()) { 13 | didSet { 14 | setNeedsDisplay() 15 | } 16 | } 17 | 18 | public override func drawRect(rect: CGRect) { 19 | fillWithGradient(gradient, context: UIGraphicsGetCurrentContext()) 20 | super.drawRect(rect) 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /TouchGradientPicker/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 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /TouchGradientPicker/Pan.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Pan.swift 3 | // TouchGradientPicker 4 | // 5 | // Created by Mike Mertsock on 8/20/15. 6 | // Copyright (c) 2015 Esker Apps. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public struct Pan { 12 | // values in the range [-1, 1], describes the amount of distance the 13 | // user swiped relative to the size of the containing view. 14 | // A value of 1 means the user swiped all the way to the right or down, 15 | // a value of -1 means the user swiped all the way to the left or down, 16 | // 0.25 means the user swiped 1/4 the distance. 17 | public let horizontal: CGFloat 18 | public let vertical: CGFloat 19 | 20 | public func scaled(factor: CGFloat) -> Pan { 21 | return Pan(horizontal: factor * horizontal, vertical: factor * vertical) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /TouchGradientPicker/TouchGradientPicker.h: -------------------------------------------------------------------------------- 1 | // 2 | // TouchGradientPicker.h 3 | // TouchGradientPicker 4 | // 5 | // Created by Mike Mertsock on 8/19/15. 6 | // Copyright (c) 2015 Esker Apps. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for TouchGradientPicker. 12 | FOUNDATION_EXPORT double TouchGradientPickerVersionNumber; 13 | 14 | //! Project version string for TouchGradientPicker. 15 | FOUNDATION_EXPORT const unsigned char TouchGradientPickerVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /TouchGradientPicker/TouchGradientPicker.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TouchGradientPicker.swift 3 | // TouchGradientPicker 4 | // 5 | // Created by Mike Mertsock on 8/19/15. 6 | // Copyright (c) 2015 Esker Apps. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public class TouchGradientPicker: UIView { 12 | 13 | @IBOutlet public var gradientView: GradientView! 14 | 15 | public var gradientBuilder: GradientBuilder? 16 | private var panStartValue: GradientType? 17 | 18 | public required init?(coder aDecoder: NSCoder) { 19 | super.init(coder: aDecoder) 20 | setUpGestureRecognizers() 21 | } 22 | 23 | public override init(frame: CGRect) { 24 | super.init(frame: frame) 25 | setUpGestureRecognizers() 26 | } 27 | 28 | private func setUpGestureRecognizers() { 29 | let recognizer = UIPanGestureRecognizer(target: self, action: "didPan:") 30 | addGestureRecognizer(recognizer) 31 | } 32 | 33 | func didPan(sender: UIPanGestureRecognizer!) { 34 | switch (sender.state) { 35 | case .Began: 36 | panStartValue = gradientView.gradient 37 | case .Changed: 38 | if let pan = panFromGesture(sender), 39 | newGradient = gradientBuilder?.gradientFromPan(pan, panStartValue: panStartValue ?? gradientView.gradient) { 40 | gradientView.gradient = newGradient 41 | } 42 | case .Ended: 43 | panStartValue = nil 44 | default: 45 | break 46 | } 47 | } 48 | 49 | func panFromGesture(gesture: UIPanGestureRecognizer) -> Pan? { 50 | let viewTx = gesture.translationInView(self) 51 | 52 | // normalize both directions to [-1, 1] 53 | let panBounds = bounds 54 | if panBounds.width < 1 || panBounds.height < 1 { 55 | return nil 56 | } 57 | 58 | let normalized = CGPointMake(viewTx.x / panBounds.width, viewTx.y / panBounds.height) 59 | 60 | return Pan(horizontal: normalized.x, vertical: normalized.y) 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /TouchGradientPicker/UIColorExtensions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIColorExtensions.swift 3 | // TouchGradientPicker 4 | // 5 | // Created by Mike Mertsock on 8/19/15. 6 | // Copyright (c) 2015 Esker Apps. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | public extension UIColor { 12 | public func getHSBAComponents() -> (CGFloat, CGFloat, CGFloat, CGFloat) { 13 | var h: CGFloat = 0, s: CGFloat = 0, b: CGFloat = 0, a: CGFloat = 0 14 | getHue(&h, saturation: &s, brightness: &b, alpha: &a) 15 | return (h, s, b, a) 16 | } 17 | 18 | public func colorWithHueComponent(newHue: CGFloat) -> UIColor { 19 | let (_, s, b, a) = getHSBAComponents() 20 | var clampedHue = newHue 21 | if clampedHue > 1 { clampedHue = clampedHue - floor(newHue) } 22 | if clampedHue < 0 { clampedHue = clampedHue + ceil(abs(newHue)) } 23 | let newColor = UIColor(hue: clampedHue, saturation: s, brightness: b, alpha: a) 24 | return newColor 25 | } 26 | 27 | public func colorWithBrightnessComponent(newBrightness: CGFloat) -> UIColor { 28 | let (h, s, _, a) = getHSBAComponents() 29 | return UIColor(hue: h, saturation: s, brightness: newBrightness, alpha: a) 30 | } 31 | 32 | public func colorWithSaturationComponent(newSaturation: CGFloat) -> UIColor { 33 | let (h, _, b, a) = getHSBAComponents() 34 | return UIColor(hue: h, saturation: newSaturation, brightness: b, alpha: a) 35 | } 36 | 37 | public var hue: CGFloat { 38 | let (h, _, _, _) = getHSBAComponents() 39 | return h 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /TouchGradientPickerDemo/TouchGradientPickerDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 2786BB6C1B85694100AEAB41 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2786BB6B1B85694100AEAB41 /* AppDelegate.swift */; }; 11 | 2786BB6E1B85694100AEAB41 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2786BB6D1B85694100AEAB41 /* ViewController.swift */; }; 12 | 2786BB711B85694100AEAB41 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 2786BB6F1B85694100AEAB41 /* Main.storyboard */; }; 13 | 2786BB731B85694100AEAB41 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2786BB721B85694100AEAB41 /* Images.xcassets */; }; 14 | 2786BB761B85694100AEAB41 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2786BB741B85694100AEAB41 /* LaunchScreen.xib */; }; 15 | 2786BB821B85694100AEAB41 /* TouchGradientPickerDemoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2786BB811B85694100AEAB41 /* TouchGradientPickerDemoTests.swift */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXContainerItemProxy section */ 19 | 2786BB7C1B85694100AEAB41 /* PBXContainerItemProxy */ = { 20 | isa = PBXContainerItemProxy; 21 | containerPortal = 2786BB5E1B85694100AEAB41 /* Project object */; 22 | proxyType = 1; 23 | remoteGlobalIDString = 2786BB651B85694100AEAB41; 24 | remoteInfo = TouchGradientPickerDemo; 25 | }; 26 | /* End PBXContainerItemProxy section */ 27 | 28 | /* Begin PBXFileReference section */ 29 | 2786BB661B85694100AEAB41 /* TouchGradientPickerDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TouchGradientPickerDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 30 | 2786BB6A1B85694100AEAB41 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 31 | 2786BB6B1B85694100AEAB41 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 32 | 2786BB6D1B85694100AEAB41 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 33 | 2786BB701B85694100AEAB41 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 34 | 2786BB721B85694100AEAB41 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 35 | 2786BB751B85694100AEAB41 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 36 | 2786BB7B1B85694100AEAB41 /* TouchGradientPickerDemoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TouchGradientPickerDemoTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 37 | 2786BB801B85694100AEAB41 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 38 | 2786BB811B85694100AEAB41 /* TouchGradientPickerDemoTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TouchGradientPickerDemoTests.swift; sourceTree = ""; }; 39 | /* End PBXFileReference section */ 40 | 41 | /* Begin PBXFrameworksBuildPhase section */ 42 | 2786BB631B85694100AEAB41 /* Frameworks */ = { 43 | isa = PBXFrameworksBuildPhase; 44 | buildActionMask = 2147483647; 45 | files = ( 46 | ); 47 | runOnlyForDeploymentPostprocessing = 0; 48 | }; 49 | 2786BB781B85694100AEAB41 /* Frameworks */ = { 50 | isa = PBXFrameworksBuildPhase; 51 | buildActionMask = 2147483647; 52 | files = ( 53 | ); 54 | runOnlyForDeploymentPostprocessing = 0; 55 | }; 56 | /* End PBXFrameworksBuildPhase section */ 57 | 58 | /* Begin PBXGroup section */ 59 | 2786BB5D1B85694100AEAB41 = { 60 | isa = PBXGroup; 61 | children = ( 62 | 2786BB681B85694100AEAB41 /* TouchGradientPickerDemo */, 63 | 2786BB7E1B85694100AEAB41 /* TouchGradientPickerDemoTests */, 64 | 2786BB671B85694100AEAB41 /* Products */, 65 | ); 66 | sourceTree = ""; 67 | }; 68 | 2786BB671B85694100AEAB41 /* Products */ = { 69 | isa = PBXGroup; 70 | children = ( 71 | 2786BB661B85694100AEAB41 /* TouchGradientPickerDemo.app */, 72 | 2786BB7B1B85694100AEAB41 /* TouchGradientPickerDemoTests.xctest */, 73 | ); 74 | name = Products; 75 | sourceTree = ""; 76 | }; 77 | 2786BB681B85694100AEAB41 /* TouchGradientPickerDemo */ = { 78 | isa = PBXGroup; 79 | children = ( 80 | 2786BB6B1B85694100AEAB41 /* AppDelegate.swift */, 81 | 2786BB721B85694100AEAB41 /* Images.xcassets */, 82 | 2786BB741B85694100AEAB41 /* LaunchScreen.xib */, 83 | 2786BB6F1B85694100AEAB41 /* Main.storyboard */, 84 | 2786BB691B85694100AEAB41 /* Supporting Files */, 85 | 2786BB6D1B85694100AEAB41 /* ViewController.swift */, 86 | ); 87 | path = TouchGradientPickerDemo; 88 | sourceTree = ""; 89 | }; 90 | 2786BB691B85694100AEAB41 /* Supporting Files */ = { 91 | isa = PBXGroup; 92 | children = ( 93 | 2786BB6A1B85694100AEAB41 /* Info.plist */, 94 | ); 95 | name = "Supporting Files"; 96 | sourceTree = ""; 97 | }; 98 | 2786BB7E1B85694100AEAB41 /* TouchGradientPickerDemoTests */ = { 99 | isa = PBXGroup; 100 | children = ( 101 | 2786BB811B85694100AEAB41 /* TouchGradientPickerDemoTests.swift */, 102 | 2786BB7F1B85694100AEAB41 /* Supporting Files */, 103 | ); 104 | path = TouchGradientPickerDemoTests; 105 | sourceTree = ""; 106 | }; 107 | 2786BB7F1B85694100AEAB41 /* Supporting Files */ = { 108 | isa = PBXGroup; 109 | children = ( 110 | 2786BB801B85694100AEAB41 /* Info.plist */, 111 | ); 112 | name = "Supporting Files"; 113 | sourceTree = ""; 114 | }; 115 | /* End PBXGroup section */ 116 | 117 | /* Begin PBXNativeTarget section */ 118 | 2786BB651B85694100AEAB41 /* TouchGradientPickerDemo */ = { 119 | isa = PBXNativeTarget; 120 | buildConfigurationList = 2786BB851B85694100AEAB41 /* Build configuration list for PBXNativeTarget "TouchGradientPickerDemo" */; 121 | buildPhases = ( 122 | 2786BB621B85694100AEAB41 /* Sources */, 123 | 2786BB631B85694100AEAB41 /* Frameworks */, 124 | 2786BB641B85694100AEAB41 /* Resources */, 125 | ); 126 | buildRules = ( 127 | ); 128 | dependencies = ( 129 | ); 130 | name = TouchGradientPickerDemo; 131 | productName = TouchGradientPickerDemo; 132 | productReference = 2786BB661B85694100AEAB41 /* TouchGradientPickerDemo.app */; 133 | productType = "com.apple.product-type.application"; 134 | }; 135 | 2786BB7A1B85694100AEAB41 /* TouchGradientPickerDemoTests */ = { 136 | isa = PBXNativeTarget; 137 | buildConfigurationList = 2786BB881B85694100AEAB41 /* Build configuration list for PBXNativeTarget "TouchGradientPickerDemoTests" */; 138 | buildPhases = ( 139 | 2786BB771B85694100AEAB41 /* Sources */, 140 | 2786BB781B85694100AEAB41 /* Frameworks */, 141 | 2786BB791B85694100AEAB41 /* Resources */, 142 | ); 143 | buildRules = ( 144 | ); 145 | dependencies = ( 146 | 2786BB7D1B85694100AEAB41 /* PBXTargetDependency */, 147 | ); 148 | name = TouchGradientPickerDemoTests; 149 | productName = TouchGradientPickerDemoTests; 150 | productReference = 2786BB7B1B85694100AEAB41 /* TouchGradientPickerDemoTests.xctest */; 151 | productType = "com.apple.product-type.bundle.unit-test"; 152 | }; 153 | /* End PBXNativeTarget section */ 154 | 155 | /* Begin PBXProject section */ 156 | 2786BB5E1B85694100AEAB41 /* Project object */ = { 157 | isa = PBXProject; 158 | attributes = { 159 | LastSwiftUpdateCheck = 0700; 160 | LastUpgradeCheck = 0700; 161 | ORGANIZATIONNAME = "Esker Apps"; 162 | TargetAttributes = { 163 | 2786BB651B85694100AEAB41 = { 164 | CreatedOnToolsVersion = 6.4; 165 | }; 166 | 2786BB7A1B85694100AEAB41 = { 167 | CreatedOnToolsVersion = 6.4; 168 | TestTargetID = 2786BB651B85694100AEAB41; 169 | }; 170 | }; 171 | }; 172 | buildConfigurationList = 2786BB611B85694100AEAB41 /* Build configuration list for PBXProject "TouchGradientPickerDemo" */; 173 | compatibilityVersion = "Xcode 3.2"; 174 | developmentRegion = English; 175 | hasScannedForEncodings = 0; 176 | knownRegions = ( 177 | en, 178 | Base, 179 | ); 180 | mainGroup = 2786BB5D1B85694100AEAB41; 181 | productRefGroup = 2786BB671B85694100AEAB41 /* Products */; 182 | projectDirPath = ""; 183 | projectRoot = ""; 184 | targets = ( 185 | 2786BB651B85694100AEAB41 /* TouchGradientPickerDemo */, 186 | 2786BB7A1B85694100AEAB41 /* TouchGradientPickerDemoTests */, 187 | ); 188 | }; 189 | /* End PBXProject section */ 190 | 191 | /* Begin PBXResourcesBuildPhase section */ 192 | 2786BB641B85694100AEAB41 /* Resources */ = { 193 | isa = PBXResourcesBuildPhase; 194 | buildActionMask = 2147483647; 195 | files = ( 196 | 2786BB711B85694100AEAB41 /* Main.storyboard in Resources */, 197 | 2786BB761B85694100AEAB41 /* LaunchScreen.xib in Resources */, 198 | 2786BB731B85694100AEAB41 /* Images.xcassets in Resources */, 199 | ); 200 | runOnlyForDeploymentPostprocessing = 0; 201 | }; 202 | 2786BB791B85694100AEAB41 /* Resources */ = { 203 | isa = PBXResourcesBuildPhase; 204 | buildActionMask = 2147483647; 205 | files = ( 206 | ); 207 | runOnlyForDeploymentPostprocessing = 0; 208 | }; 209 | /* End PBXResourcesBuildPhase section */ 210 | 211 | /* Begin PBXSourcesBuildPhase section */ 212 | 2786BB621B85694100AEAB41 /* Sources */ = { 213 | isa = PBXSourcesBuildPhase; 214 | buildActionMask = 2147483647; 215 | files = ( 216 | 2786BB6E1B85694100AEAB41 /* ViewController.swift in Sources */, 217 | 2786BB6C1B85694100AEAB41 /* AppDelegate.swift in Sources */, 218 | ); 219 | runOnlyForDeploymentPostprocessing = 0; 220 | }; 221 | 2786BB771B85694100AEAB41 /* Sources */ = { 222 | isa = PBXSourcesBuildPhase; 223 | buildActionMask = 2147483647; 224 | files = ( 225 | 2786BB821B85694100AEAB41 /* TouchGradientPickerDemoTests.swift in Sources */, 226 | ); 227 | runOnlyForDeploymentPostprocessing = 0; 228 | }; 229 | /* End PBXSourcesBuildPhase section */ 230 | 231 | /* Begin PBXTargetDependency section */ 232 | 2786BB7D1B85694100AEAB41 /* PBXTargetDependency */ = { 233 | isa = PBXTargetDependency; 234 | target = 2786BB651B85694100AEAB41 /* TouchGradientPickerDemo */; 235 | targetProxy = 2786BB7C1B85694100AEAB41 /* PBXContainerItemProxy */; 236 | }; 237 | /* End PBXTargetDependency section */ 238 | 239 | /* Begin PBXVariantGroup section */ 240 | 2786BB6F1B85694100AEAB41 /* Main.storyboard */ = { 241 | isa = PBXVariantGroup; 242 | children = ( 243 | 2786BB701B85694100AEAB41 /* Base */, 244 | ); 245 | name = Main.storyboard; 246 | sourceTree = ""; 247 | }; 248 | 2786BB741B85694100AEAB41 /* LaunchScreen.xib */ = { 249 | isa = PBXVariantGroup; 250 | children = ( 251 | 2786BB751B85694100AEAB41 /* Base */, 252 | ); 253 | name = LaunchScreen.xib; 254 | sourceTree = ""; 255 | }; 256 | /* End PBXVariantGroup section */ 257 | 258 | /* Begin XCBuildConfiguration section */ 259 | 2786BB831B85694100AEAB41 /* Debug */ = { 260 | isa = XCBuildConfiguration; 261 | buildSettings = { 262 | ALWAYS_SEARCH_USER_PATHS = NO; 263 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 264 | CLANG_CXX_LIBRARY = "libc++"; 265 | CLANG_ENABLE_MODULES = YES; 266 | CLANG_ENABLE_OBJC_ARC = YES; 267 | CLANG_WARN_BOOL_CONVERSION = YES; 268 | CLANG_WARN_CONSTANT_CONVERSION = YES; 269 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 270 | CLANG_WARN_EMPTY_BODY = YES; 271 | CLANG_WARN_ENUM_CONVERSION = YES; 272 | CLANG_WARN_INT_CONVERSION = YES; 273 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 274 | CLANG_WARN_UNREACHABLE_CODE = YES; 275 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 276 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 277 | COPY_PHASE_STRIP = NO; 278 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 279 | ENABLE_STRICT_OBJC_MSGSEND = YES; 280 | ENABLE_TESTABILITY = YES; 281 | GCC_C_LANGUAGE_STANDARD = gnu99; 282 | GCC_DYNAMIC_NO_PIC = NO; 283 | GCC_NO_COMMON_BLOCKS = YES; 284 | GCC_OPTIMIZATION_LEVEL = 0; 285 | GCC_PREPROCESSOR_DEFINITIONS = ( 286 | "DEBUG=1", 287 | "$(inherited)", 288 | ); 289 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 290 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 291 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 292 | GCC_WARN_UNDECLARED_SELECTOR = YES; 293 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 294 | GCC_WARN_UNUSED_FUNCTION = YES; 295 | GCC_WARN_UNUSED_VARIABLE = YES; 296 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 297 | MTL_ENABLE_DEBUG_INFO = YES; 298 | ONLY_ACTIVE_ARCH = YES; 299 | SDKROOT = iphoneos; 300 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 301 | TARGETED_DEVICE_FAMILY = "1,2"; 302 | }; 303 | name = Debug; 304 | }; 305 | 2786BB841B85694100AEAB41 /* Release */ = { 306 | isa = XCBuildConfiguration; 307 | buildSettings = { 308 | ALWAYS_SEARCH_USER_PATHS = NO; 309 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 310 | CLANG_CXX_LIBRARY = "libc++"; 311 | CLANG_ENABLE_MODULES = YES; 312 | CLANG_ENABLE_OBJC_ARC = YES; 313 | CLANG_WARN_BOOL_CONVERSION = YES; 314 | CLANG_WARN_CONSTANT_CONVERSION = YES; 315 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 316 | CLANG_WARN_EMPTY_BODY = YES; 317 | CLANG_WARN_ENUM_CONVERSION = YES; 318 | CLANG_WARN_INT_CONVERSION = YES; 319 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 320 | CLANG_WARN_UNREACHABLE_CODE = YES; 321 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 322 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 323 | COPY_PHASE_STRIP = NO; 324 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 325 | ENABLE_NS_ASSERTIONS = NO; 326 | ENABLE_STRICT_OBJC_MSGSEND = YES; 327 | GCC_C_LANGUAGE_STANDARD = gnu99; 328 | GCC_NO_COMMON_BLOCKS = YES; 329 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 330 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 331 | GCC_WARN_UNDECLARED_SELECTOR = YES; 332 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 333 | GCC_WARN_UNUSED_FUNCTION = YES; 334 | GCC_WARN_UNUSED_VARIABLE = YES; 335 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 336 | MTL_ENABLE_DEBUG_INFO = NO; 337 | SDKROOT = iphoneos; 338 | TARGETED_DEVICE_FAMILY = "1,2"; 339 | VALIDATE_PRODUCT = YES; 340 | }; 341 | name = Release; 342 | }; 343 | 2786BB861B85694100AEAB41 /* Debug */ = { 344 | isa = XCBuildConfiguration; 345 | buildSettings = { 346 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 347 | INFOPLIST_FILE = TouchGradientPickerDemo/Info.plist; 348 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 349 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 350 | PRODUCT_BUNDLE_IDENTIFIER = "com.esker-apps.$(PRODUCT_NAME:rfc1034identifier)"; 351 | PRODUCT_NAME = "$(TARGET_NAME)"; 352 | }; 353 | name = Debug; 354 | }; 355 | 2786BB871B85694100AEAB41 /* Release */ = { 356 | isa = XCBuildConfiguration; 357 | buildSettings = { 358 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 359 | INFOPLIST_FILE = TouchGradientPickerDemo/Info.plist; 360 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 361 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 362 | PRODUCT_BUNDLE_IDENTIFIER = "com.esker-apps.$(PRODUCT_NAME:rfc1034identifier)"; 363 | PRODUCT_NAME = "$(TARGET_NAME)"; 364 | }; 365 | name = Release; 366 | }; 367 | 2786BB891B85694100AEAB41 /* Debug */ = { 368 | isa = XCBuildConfiguration; 369 | buildSettings = { 370 | BUNDLE_LOADER = "$(TEST_HOST)"; 371 | FRAMEWORK_SEARCH_PATHS = ( 372 | "$(SDKROOT)/Developer/Library/Frameworks", 373 | "$(inherited)", 374 | ); 375 | GCC_PREPROCESSOR_DEFINITIONS = ( 376 | "DEBUG=1", 377 | "$(inherited)", 378 | ); 379 | INFOPLIST_FILE = TouchGradientPickerDemoTests/Info.plist; 380 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 381 | PRODUCT_BUNDLE_IDENTIFIER = "com.esker-apps.$(PRODUCT_NAME:rfc1034identifier)"; 382 | PRODUCT_NAME = "$(TARGET_NAME)"; 383 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TouchGradientPickerDemo.app/TouchGradientPickerDemo"; 384 | }; 385 | name = Debug; 386 | }; 387 | 2786BB8A1B85694100AEAB41 /* Release */ = { 388 | isa = XCBuildConfiguration; 389 | buildSettings = { 390 | BUNDLE_LOADER = "$(TEST_HOST)"; 391 | FRAMEWORK_SEARCH_PATHS = ( 392 | "$(SDKROOT)/Developer/Library/Frameworks", 393 | "$(inherited)", 394 | ); 395 | INFOPLIST_FILE = TouchGradientPickerDemoTests/Info.plist; 396 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 397 | PRODUCT_BUNDLE_IDENTIFIER = "com.esker-apps.$(PRODUCT_NAME:rfc1034identifier)"; 398 | PRODUCT_NAME = "$(TARGET_NAME)"; 399 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TouchGradientPickerDemo.app/TouchGradientPickerDemo"; 400 | }; 401 | name = Release; 402 | }; 403 | /* End XCBuildConfiguration section */ 404 | 405 | /* Begin XCConfigurationList section */ 406 | 2786BB611B85694100AEAB41 /* Build configuration list for PBXProject "TouchGradientPickerDemo" */ = { 407 | isa = XCConfigurationList; 408 | buildConfigurations = ( 409 | 2786BB831B85694100AEAB41 /* Debug */, 410 | 2786BB841B85694100AEAB41 /* Release */, 411 | ); 412 | defaultConfigurationIsVisible = 0; 413 | defaultConfigurationName = Release; 414 | }; 415 | 2786BB851B85694100AEAB41 /* Build configuration list for PBXNativeTarget "TouchGradientPickerDemo" */ = { 416 | isa = XCConfigurationList; 417 | buildConfigurations = ( 418 | 2786BB861B85694100AEAB41 /* Debug */, 419 | 2786BB871B85694100AEAB41 /* Release */, 420 | ); 421 | defaultConfigurationIsVisible = 0; 422 | defaultConfigurationName = Release; 423 | }; 424 | 2786BB881B85694100AEAB41 /* Build configuration list for PBXNativeTarget "TouchGradientPickerDemoTests" */ = { 425 | isa = XCConfigurationList; 426 | buildConfigurations = ( 427 | 2786BB891B85694100AEAB41 /* Debug */, 428 | 2786BB8A1B85694100AEAB41 /* Release */, 429 | ); 430 | defaultConfigurationIsVisible = 0; 431 | defaultConfigurationName = Release; 432 | }; 433 | /* End XCConfigurationList section */ 434 | }; 435 | rootObject = 2786BB5E1B85694100AEAB41 /* Project object */; 436 | } 437 | -------------------------------------------------------------------------------- /TouchGradientPickerDemo/TouchGradientPickerDemo/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // TouchGradientPickerDemo 4 | // 5 | // Created by Mike Mertsock on 8/19/15. 6 | // Copyright (c) 2015 Esker Apps. 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: [NSObject: AnyObject]?) -> 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 throttle down OpenGL ES frame rates. 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 inactive 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 | -------------------------------------------------------------------------------- /TouchGradientPickerDemo/TouchGradientPickerDemo/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /TouchGradientPickerDemo/TouchGradientPickerDemo/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 | 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 | -------------------------------------------------------------------------------- /TouchGradientPickerDemo/TouchGradientPickerDemo/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /TouchGradientPickerDemo/TouchGradientPickerDemo/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 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | UISupportedInterfaceOrientations~ipad 40 | 41 | UIInterfaceOrientationPortrait 42 | UIInterfaceOrientationPortraitUpsideDown 43 | UIInterfaceOrientationLandscapeLeft 44 | UIInterfaceOrientationLandscapeRight 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /TouchGradientPickerDemo/TouchGradientPickerDemo/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // TouchGradientPickerDemo 4 | // 5 | // Created by Mike Mertsock on 8/19/15. 6 | // Copyright (c) 2015 Esker Apps. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import TouchGradientPicker 11 | 12 | class ViewController: UIViewController { 13 | 14 | // Storyboard: 15 | // Add a UIView with custom class GradientView 16 | // Add a UIView with custom class TouchGradientPicker 17 | // Set up outlets from this view controller to the two views 18 | // Set up an outlet from the TouchGradientPicker to the GradientView 19 | 20 | // The two views can have identical size and position if you want the 21 | // gestures to cover the full area of the gradient, or they can be 22 | // laid out independently in any way you wish. 23 | 24 | @IBOutlet var gradientView: GradientView! 25 | @IBOutlet var picker: TouchGradientPicker! 26 | 27 | override func viewDidLoad() { 28 | super.viewDidLoad() 29 | initializeGradientBuilder(0) 30 | } 31 | 32 | private func initializeGradientBuilder(mode: Int) { 33 | switch (mode) { 34 | case 0: setUpHueHueVarianceBuilder() 35 | case 1: setUpSatAlphaVarianceBuilder() 36 | default: break 37 | } 38 | } 39 | 40 | private func setUpHueHueVarianceBuilder() { 41 | demoExplanationLabel.text = "Swipe L/R to change hue, U/D to change hue variance" 42 | 43 | // Initialize the gradient view and builder 44 | 45 | let initialCenter = UIColor(hue: 0.9, saturation: 0.45, brightness: 0.86, alpha: 1) 46 | let initialValue = CenterColorGradient(centerColor: initialCenter, hueVariance: 0.09, satVariance: 0, brightnessVariance: 0, alphaVariance: 0) 47 | gradientView.gradient = initialValue 48 | 49 | let builder = CenterColorGradientBuilder(initialValue: initialValue) 50 | 51 | // Horizontal pan gestures: change the average hue of the gradient 52 | 53 | builder.centerColor.hue = { 54 | pan, currentValue in 55 | // Square the value so small swipes = smaller adjustments, 56 | // for easier fine adjustment. 57 | let newHue = currentValue + pan.horizontal * pan.horizontal * (pan.horizontal < 0 ? -1 : 1) 58 | return newHue 59 | } 60 | 61 | // Vertical pan gestures: change the "spread" of the gradient 62 | 63 | let maxHueVarianceMagnitude: CGFloat = 0.35 // Cap the maximum amount of hue variance 64 | builder.hueVariance = clamp({ 65 | pan, currentValue in 66 | // Reverse the direction of the swipe 67 | currentValue + pan.scaled(-maxHueVarianceMagnitude).vertical 68 | }, minValue: -maxHueVarianceMagnitude, maxValue: maxHueVarianceMagnitude) 69 | 70 | picker.gradientBuilder = builder 71 | } 72 | 73 | private func setUpSatAlphaVarianceBuilder() { 74 | demoExplanationLabel.text = "Swipe L/R to change saturation, U/D to change contrast" 75 | 76 | // Initialize the gradient view and builder 77 | 78 | let centerHue: CGFloat = 0.64 79 | let initialCenter = UIColor(hue: centerHue, saturation: 0.5, brightness: 0.6, alpha: 0.7) 80 | let initialValue = CenterColorGradient(centerColor: initialCenter, hueVariance: 0, satVariance: 0, brightnessVariance: -0.2, alphaVariance: 0) 81 | gradientView.gradient = initialValue 82 | 83 | let builder = CenterColorGradientBuilder(initialValue: initialValue) 84 | 85 | // Horizontal pan gestures: change the average saturation of the gradient 86 | 87 | builder.centerColor.saturation = { 88 | pan, currentValue in 89 | // Reverse the direction of the swipe 90 | currentValue - pan.horizontal 91 | } 92 | 93 | // Vertical pan gestures: vary the brightness AND alpha at either end of the gradient 94 | 95 | let maxBrightnessVarianceMagnitude: CGFloat = 0.4 // Cap the maximum amount of contrast 96 | builder.brightnessVariance = clamp({ 97 | pan, currentValue in 98 | currentValue + pan.scaled(maxBrightnessVarianceMagnitude).vertical 99 | }, minValue: -maxBrightnessVarianceMagnitude, maxValue: maxBrightnessVarianceMagnitude) 100 | 101 | let maxAlphaVarianceMagnitude: CGFloat = 0.3 102 | builder.alphaVariance = clamp({ 103 | pan, currentValue in 104 | currentValue + pan.scaled(maxAlphaVarianceMagnitude).vertical 105 | }, minValue: -maxAlphaVarianceMagnitude, maxValue: maxAlphaVarianceMagnitude) 106 | 107 | // Keep the hue pegged at a single value 108 | // (extreme brightness/saturation values can cause the original hue to be lost) 109 | builder.centerColor.hue = { pan, currentValue in centerHue } 110 | 111 | picker.gradientBuilder = builder 112 | } 113 | 114 | // Outlets and actions for playing with the demo 115 | 116 | @IBOutlet var demoExplanationLabel: UILabel! 117 | @IBAction func builderSetupSelected(segmentedControl: UISegmentedControl!) { 118 | initializeGradientBuilder(segmentedControl.selectedSegmentIndex) 119 | } 120 | } 121 | 122 | func clamp(valueFunc: (Pan, T) -> T, minValue: T, maxValue: T) -> (Pan, T) -> T { 123 | return { 124 | pan, value in 125 | let newValue = valueFunc(pan, value) 126 | return max(minValue, min(maxValue, newValue)) 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /TouchGradientPickerDemo/TouchGradientPickerDemoTests/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 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /TouchGradientPickerDemo/TouchGradientPickerDemoTests/TouchGradientPickerDemoTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TouchGradientPickerDemoTests.swift 3 | // TouchGradientPickerDemoTests 4 | // 5 | // Created by Mike Mertsock on 8/19/15. 6 | // Copyright (c) 2015 Esker Apps. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import XCTest 11 | 12 | class TouchGradientPickerDemoTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | XCTAssert(true, "Pass") 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measureBlock() { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /TouchGradientPickerTests/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 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /TouchGradientPickerTests/TouchGradientPickerTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TouchGradientPickerTests.swift 3 | // TouchGradientPickerTests 4 | // 5 | // Created by Mike Mertsock on 8/19/15. 6 | // Copyright (c) 2015 Esker Apps. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import XCTest 11 | 12 | class TouchGradientPickerTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | XCTAssert(true, "Pass") 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measureBlock() { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | --------------------------------------------------------------------------------