Updated default element sizings. Updated picker delegate.

This commit is contained in:
Jonathan Cardasis 2019-05-02 10:29:52 -04:00
parent b60527a81e
commit 520d4d64a7
6 changed files with 25 additions and 24 deletions

View File

@ -25,7 +25,7 @@
FC4387DE226974FD00F739F1 /* UIColor+Brightness.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC4387DC226972EB00F739F1 /* UIColor+Brightness.swift */; }; FC4387DE226974FD00F739F1 /* UIColor+Brightness.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC4387DC226972EB00F739F1 /* UIColor+Brightness.swift */; };
FCCA42A5226022A800BE2FF9 /* ColorWheelView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCCA42A4226022A800BE2FF9 /* ColorWheelView.swift */; }; FCCA42A5226022A800BE2FF9 /* ColorWheelView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCCA42A4226022A800BE2FF9 /* ColorWheelView.swift */; };
FCCA42A7226023F000BE2FF9 /* ChromaColorHandle.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCCA42A6226023F000BE2FF9 /* ChromaColorHandle.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 */; }; FCEA4E272235AAA200C0A1B6 /* ChromaColorPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = FCEA4E262235AAA200C0A1B6 /* ChromaColorPicker.swift */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
@ -87,7 +87,7 @@
FC4387DC226972EB00F739F1 /* UIColor+Brightness.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Brightness.swift"; sourceTree = "<group>"; }; FC4387DC226972EB00F739F1 /* UIColor+Brightness.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Brightness.swift"; sourceTree = "<group>"; };
FCCA42A4226022A800BE2FF9 /* ColorWheelView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorWheelView.swift; sourceTree = "<group>"; }; FCCA42A4226022A800BE2FF9 /* ColorWheelView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorWheelView.swift; sourceTree = "<group>"; };
FCCA42A6226023F000BE2FF9 /* ChromaColorHandle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChromaColorHandle.swift; sourceTree = "<group>"; }; FCCA42A6226023F000BE2FF9 /* ChromaColorHandle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChromaColorHandle.swift; sourceTree = "<group>"; };
FCCA42A92260329900BE2FF9 /* UIKit+DropShadow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIKit+DropShadow.swift"; sourceTree = "<group>"; }; FCCA42A92260329900BE2FF9 /* UIView+DropShadow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+DropShadow.swift"; sourceTree = "<group>"; };
FCCA42AB226038A400BE2FF9 /* ColorWheelViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorWheelViewTests.swift; sourceTree = "<group>"; }; FCCA42AB226038A400BE2FF9 /* ColorWheelViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorWheelViewTests.swift; sourceTree = "<group>"; };
FCEA4E262235AAA200C0A1B6 /* ChromaColorPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChromaColorPicker.swift; sourceTree = "<group>"; }; FCEA4E262235AAA200C0A1B6 /* ChromaColorPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChromaColorPicker.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
@ -205,7 +205,7 @@
FCCA42A82260325F00BE2FF9 /* Extensions */ = { FCCA42A82260325F00BE2FF9 /* Extensions */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
FCCA42A92260329900BE2FF9 /* UIKit+DropShadow.swift */, FCCA42A92260329900BE2FF9 /* UIView+DropShadow.swift */,
FC4387DC226972EB00F739F1 /* UIColor+Brightness.swift */, FC4387DC226972EB00F739F1 /* UIColor+Brightness.swift */,
); );
path = Extensions; path = Extensions;
@ -368,7 +368,7 @@
files = ( files = (
FCEA4E272235AAA200C0A1B6 /* ChromaColorPicker.swift in Sources */, FCEA4E272235AAA200C0A1B6 /* ChromaColorPicker.swift in Sources */,
FC4387CD2262B82600F739F1 /* ChromaControlStylable.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 */, FC4387DE226974FD00F739F1 /* UIColor+Brightness.swift in Sources */,
FC4387C62262556600F739F1 /* ChromaBrightnessSlider.swift in Sources */, FC4387C62262556600F739F1 /* ChromaBrightnessSlider.swift in Sources */,
FCCA42A7226023F000BE2FF9 /* ChromaColorHandle.swift in Sources */, FCCA42A7226023F000BE2FF9 /* ChromaColorHandle.swift in Sources */,

View File

@ -41,7 +41,7 @@ class ViewController: UIViewController {
brightnessSlider.connect(to: colorPicker) brightnessSlider.connect(to: colorPicker)
// Style // Style
brightnessSlider.trackColor = UIColor.red brightnessSlider.trackColor = UIColor.blue
brightnessSlider.handle.borderWidth = 3.0 // Example of customizing the handle's properties. brightnessSlider.handle.borderWidth = 3.0 // Example of customizing the handle's properties.
// Layout // Layout
@ -57,24 +57,29 @@ class ViewController: UIViewController {
} }
private func setupColorPickerHandles() { 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 // Setup custom handle view with insets
let customImageView = UIImageView(image: #imageLiteral(resourceName: "home").withRenderingMode(.alwaysTemplate)) let customImageView = UIImageView(image: #imageLiteral(resourceName: "home").withRenderingMode(.alwaysTemplate))
customImageView.contentMode = .scaleAspectFit customImageView.contentMode = .scaleAspectFit
customImageView.tintColor = .white customImageView.tintColor = .white
homeHandle.accessoryView = customImageView homeHandle.accessoryView = customImageView
homeHandle.accessoryViewEdgeInsets = UIEdgeInsets(top: 0, left: 2, bottom: 2, right: 2) homeHandle.accessoryViewEdgeInsets = UIEdgeInsets(top: 2, left: 4, bottom: 4, right: 4)
colorPicker.addHandle(at: .red)
} }
} }
extension ViewController: ChromaColorPickerDelegate { extension ViewController: ChromaColorPickerDelegate {
func colorPickerHandleDidChange(_ colorPicker: ChromaColorPicker, handle: ChromaColorHandle, to color: UIColor) {
func colorPickerDidChooseColor(_ colorPicker: ChromaColorPicker, color: UIColor) {
colorDisplayView.backgroundColor = color colorDisplayView.backgroundColor = color
} }
} }

View File

@ -10,8 +10,8 @@ import UIKit
import Accelerate import Accelerate
public protocol ChromaColorPickerDelegate: class { public protocol ChromaColorPickerDelegate: class {
/// When the control has changed /// When a handle's value has changed.
func colorPickerDidChooseColor(_ colorPicker: ChromaColorPicker, color: UIColor) func colorPickerHandleDidChange(_ colorPicker: ChromaColorPicker, handle: ChromaColorHandle, to color: UIColor)
} }
@ -91,6 +91,7 @@ public class ChromaColorPicker: UIControl, ChromaControlStylable {
public func addHandle(_ handle: ChromaColorHandle) { public func addHandle(_ handle: ChromaColorHandle) {
handles.append(handle) handles.append(handle)
colorWheelView.addSubview(handle) colorWheelView.addSubview(handle)
brightnessSlider?.trackColor = handle.color
} }
public func connect(_ slider: ChromaBrightnessSlider) { public func connect(_ slider: ChromaBrightnessSlider) {
@ -214,8 +215,8 @@ public class ChromaColorPicker: UIControl, ChromaControlStylable {
informDelegateOfColorChange(on: currentHandle) informDelegateOfColorChange(on: currentHandle)
} }
internal func informDelegateOfColorChange(on handle: ChromaColorHandle) { internal func informDelegateOfColorChange(on handle: ChromaColorHandle) { // TEMP:
delegate?.colorPickerDidChooseColor(self, color: handle.color) delegate?.colorPickerHandleDidChange(self, handle: handle, to: handle.color)
} }
// MARK: - Helpers // MARK: - Helpers
@ -247,4 +248,4 @@ public class ChromaColorPicker: UIControl, ChromaControlStylable {
} }
internal let defaultHandleColorPosition: UIColor = .white internal let defaultHandleColorPosition: UIColor = .white
internal let defaultHandleSize: CGSize = CGSize(width: 34, height: 42) internal let defaultHandleSize: CGSize = CGSize(width: 42, height: 52)

View File

@ -1,5 +1,5 @@
// //
// UIKit+DropShadow.swift // UIView+DropShadow.swift
// ChromaColorPicker // ChromaColorPicker
// //
// Created by Jon Cardasis on 4/11/19. // Created by Jon Cardasis on 4/11/19.

View File

@ -16,10 +16,6 @@ class ChromaColorPickerTests: XCTestCase {
subject = ChromaColorPicker(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) subject = ChromaColorPicker(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
} }
func testTapGestureRecognizerIsAddedToColorWheelOnInitialization() {
XCTAssertEqual(subject.colorWheelView.gestureRecognizers?.count, 1)
}
func testConnectingSliderAddsEventTarget() { func testConnectingSliderAddsEventTarget() {
// Given // Given
let slider = ChromaBrightnessSlider(frame: .zero) let slider = ChromaBrightnessSlider(frame: .zero)

View File

@ -55,13 +55,12 @@ class ColorWheelViewTests: XCTestCase {
func testColorWheelImageIsGeneratedEveryLayoutCycle() { func testColorWheelImageIsGeneratedEveryLayoutCycle() {
// Given // Given
let width: CGFloat = 200.0 let width: CGFloat = 200.0
let screenScalar: CGFloat = UIScreen.main.scale let expectedFinalSize = CGSize(width: width, height: width)
let expectedFinalSize = CGSize(width: width * screenScalar, height: width * screenScalar)
// When // When
subject.layoutSubviews() subject.layoutSubviews()
let firstImage = subject.imageView.image! 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() subject.layoutSubviews()
let secondImage = subject.imageView.image! let secondImage = subject.imageView.image!