mirror of
https://github.com/joncardasis/ChromaColorPicker.git
synced 2024-11-26 09:33:22 +03:00
Updated default element sizings. Updated picker delegate.
This commit is contained in:
parent
b60527a81e
commit
520d4d64a7
@ -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 = "<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>"; };
|
||||
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>"; };
|
||||
FCEA4E262235AAA200C0A1B6 /* ChromaColorPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChromaColorPicker.swift; sourceTree = "<group>"; };
|
||||
/* 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 */,
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
@ -1,5 +1,5 @@
|
||||
//
|
||||
// UIKit+DropShadow.swift
|
||||
// UIView+DropShadow.swift
|
||||
// ChromaColorPicker
|
||||
//
|
||||
// Created by Jon Cardasis on 4/11/19.
|
@ -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)
|
||||
|
@ -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!
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user