diff --git a/ChromaColorPicker.xcodeproj/project.pbxproj b/ChromaColorPicker.xcodeproj/project.pbxproj index 4d6e1ba..30cad97 100644 --- a/ChromaColorPicker.xcodeproj/project.pbxproj +++ b/ChromaColorPicker.xcodeproj/project.pbxproj @@ -25,7 +25,7 @@ FC4387DE226974FD00F739F1 /* UIColor+Brightness.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC4387DC226972EB00F739F1 /* UIColor+Brightness.swift */; }; FCCA42A5226022A800BE2FF9 /* ColorWheelView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCCA42A4226022A800BE2FF9 /* ColorWheelView.swift */; }; FCCA42A7226023F000BE2FF9 /* ChromaColorHandle.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCCA42A6226023F000BE2FF9 /* ChromaColorHandle.swift */; }; - FCCA42AA2260329900BE2FF9 /* UIKit+DropShadow.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCCA42A92260329900BE2FF9 /* UIKit+DropShadow.swift */; }; + FCCA42AA2260329900BE2FF9 /* UIView+DropShadow.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCCA42A92260329900BE2FF9 /* UIView+DropShadow.swift */; }; FCEA4E272235AAA200C0A1B6 /* ChromaColorPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCEA4E262235AAA200C0A1B6 /* ChromaColorPicker.swift */; }; /* End PBXBuildFile section */ @@ -87,7 +87,7 @@ FC4387DC226972EB00F739F1 /* UIColor+Brightness.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Brightness.swift"; sourceTree = ""; }; FCCA42A4226022A800BE2FF9 /* ColorWheelView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorWheelView.swift; sourceTree = ""; }; FCCA42A6226023F000BE2FF9 /* ChromaColorHandle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChromaColorHandle.swift; sourceTree = ""; }; - FCCA42A92260329900BE2FF9 /* UIKit+DropShadow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIKit+DropShadow.swift"; sourceTree = ""; }; + FCCA42A92260329900BE2FF9 /* UIView+DropShadow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+DropShadow.swift"; sourceTree = ""; }; FCCA42AB226038A400BE2FF9 /* ColorWheelViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorWheelViewTests.swift; sourceTree = ""; }; FCEA4E262235AAA200C0A1B6 /* ChromaColorPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChromaColorPicker.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -205,7 +205,7 @@ FCCA42A82260325F00BE2FF9 /* Extensions */ = { isa = PBXGroup; children = ( - FCCA42A92260329900BE2FF9 /* UIKit+DropShadow.swift */, + FCCA42A92260329900BE2FF9 /* UIView+DropShadow.swift */, FC4387DC226972EB00F739F1 /* UIColor+Brightness.swift */, ); path = Extensions; @@ -368,7 +368,7 @@ files = ( FCEA4E272235AAA200C0A1B6 /* ChromaColorPicker.swift in Sources */, FC4387CD2262B82600F739F1 /* ChromaControlStylable.swift in Sources */, - FCCA42AA2260329900BE2FF9 /* UIKit+DropShadow.swift in Sources */, + FCCA42AA2260329900BE2FF9 /* UIView+DropShadow.swift in Sources */, FC4387DE226974FD00F739F1 /* UIColor+Brightness.swift in Sources */, FC4387C62262556600F739F1 /* ChromaBrightnessSlider.swift in Sources */, FCCA42A7226023F000BE2FF9 /* ChromaColorHandle.swift in Sources */, diff --git a/Example/ViewController.swift b/Example/ViewController.swift index ed23b7e..3d5bc76 100644 --- a/Example/ViewController.swift +++ b/Example/ViewController.swift @@ -41,7 +41,7 @@ class ViewController: UIViewController { brightnessSlider.connect(to: colorPicker) // Style - brightnessSlider.trackColor = UIColor.red + brightnessSlider.trackColor = UIColor.blue brightnessSlider.handle.borderWidth = 3.0 // Example of customizing the handle's properties. // Layout @@ -57,24 +57,29 @@ class ViewController: UIViewController { } private func setupColorPickerHandles() { - let homeHandle = colorPicker.addHandle(at: .black) + addHomeHandle() + + let peachColor = UIColor(red: 1, green: 203 / 255, blue: 164 / 255, alpha: 1) + colorPicker.addHandle(at: peachColor) + } + + private func addHomeHandle() { + let homeHandle = colorPicker.addHandle(at: .blue) // Setup custom handle view with insets let customImageView = UIImageView(image: #imageLiteral(resourceName: "home").withRenderingMode(.alwaysTemplate)) customImageView.contentMode = .scaleAspectFit customImageView.tintColor = .white homeHandle.accessoryView = customImageView - homeHandle.accessoryViewEdgeInsets = UIEdgeInsets(top: 0, left: 2, bottom: 2, right: 2) - - colorPicker.addHandle(at: .red) + homeHandle.accessoryViewEdgeInsets = UIEdgeInsets(top: 2, left: 4, bottom: 4, right: 4) } } extension ViewController: ChromaColorPickerDelegate { - - func colorPickerDidChooseColor(_ colorPicker: ChromaColorPicker, color: UIColor) { + func colorPickerHandleDidChange(_ colorPicker: ChromaColorPicker, handle: ChromaColorHandle, to color: UIColor) { colorDisplayView.backgroundColor = color } + } diff --git a/Source/ChromaColorPicker.swift b/Source/ChromaColorPicker.swift index 641d43a..f26dbec 100644 --- a/Source/ChromaColorPicker.swift +++ b/Source/ChromaColorPicker.swift @@ -10,8 +10,8 @@ import UIKit import Accelerate public protocol ChromaColorPickerDelegate: class { - /// When the control has changed - func colorPickerDidChooseColor(_ colorPicker: ChromaColorPicker, color: UIColor) + /// When a handle's value has changed. + func colorPickerHandleDidChange(_ colorPicker: ChromaColorPicker, handle: ChromaColorHandle, to color: UIColor) } @@ -91,6 +91,7 @@ public class ChromaColorPicker: UIControl, ChromaControlStylable { public func addHandle(_ handle: ChromaColorHandle) { handles.append(handle) colorWheelView.addSubview(handle) + brightnessSlider?.trackColor = handle.color } public func connect(_ slider: ChromaBrightnessSlider) { @@ -214,8 +215,8 @@ public class ChromaColorPicker: UIControl, ChromaControlStylable { informDelegateOfColorChange(on: currentHandle) } - internal func informDelegateOfColorChange(on handle: ChromaColorHandle) { - delegate?.colorPickerDidChooseColor(self, color: handle.color) + internal func informDelegateOfColorChange(on handle: ChromaColorHandle) { // TEMP: + delegate?.colorPickerHandleDidChange(self, handle: handle, to: handle.color) } // MARK: - Helpers @@ -247,4 +248,4 @@ public class ChromaColorPicker: UIControl, ChromaControlStylable { } internal let defaultHandleColorPosition: UIColor = .white -internal let defaultHandleSize: CGSize = CGSize(width: 34, height: 42) +internal let defaultHandleSize: CGSize = CGSize(width: 42, height: 52) diff --git a/Source/Extensions/UIKit+DropShadow.swift b/Source/Extensions/UIView+DropShadow.swift similarity index 98% rename from Source/Extensions/UIKit+DropShadow.swift rename to Source/Extensions/UIView+DropShadow.swift index 896555f..3be7739 100644 --- a/Source/Extensions/UIKit+DropShadow.swift +++ b/Source/Extensions/UIView+DropShadow.swift @@ -1,5 +1,5 @@ // -// UIKit+DropShadow.swift +// UIView+DropShadow.swift // ChromaColorPicker // // Created by Jon Cardasis on 4/11/19. diff --git a/Tests/ChromaColorPickerTests.swift b/Tests/ChromaColorPickerTests.swift index 2b8b6cb..a4f853d 100644 --- a/Tests/ChromaColorPickerTests.swift +++ b/Tests/ChromaColorPickerTests.swift @@ -16,10 +16,6 @@ class ChromaColorPickerTests: XCTestCase { subject = ChromaColorPicker(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) } - func testTapGestureRecognizerIsAddedToColorWheelOnInitialization() { - XCTAssertEqual(subject.colorWheelView.gestureRecognizers?.count, 1) - } - func testConnectingSliderAddsEventTarget() { // Given let slider = ChromaBrightnessSlider(frame: .zero) diff --git a/Tests/ColorWheelViewTests.swift b/Tests/ColorWheelViewTests.swift index 179691c..86b0236 100644 --- a/Tests/ColorWheelViewTests.swift +++ b/Tests/ColorWheelViewTests.swift @@ -55,13 +55,12 @@ class ColorWheelViewTests: XCTestCase { func testColorWheelImageIsGeneratedEveryLayoutCycle() { // Given let width: CGFloat = 200.0 - let screenScalar: CGFloat = UIScreen.main.scale - let expectedFinalSize = CGSize(width: width * screenScalar, height: width * screenScalar) + let expectedFinalSize = CGSize(width: width, height: width) // When subject.layoutSubviews() let firstImage = subject.imageView.image! - subject.frame = CGRect(x: 0, y: 0, width: width, height: width * 2.0) + subject.frame = CGRect(x: 0, y: 0, width: width, height: width) subject.layoutSubviews() let secondImage = subject.imageView.image!