Skip to content

Commit 49c9c3f

Browse files
authored
Merge pull request #13 from joncardasis/grayscale
Adds grayscale support to the color picker
2 parents 541fd45 + 5d37327 commit 49c9c3f

File tree

9 files changed

+294
-43
lines changed

9 files changed

+294
-43
lines changed

ChromaColorPicker-Demo.xcodeproj/project.pbxproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
3503B83E1F2689C400750356 /* ChromaAddButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C376E21D5CF9400069D7A1 /* ChromaAddButton.swift */; };
1717
3503B83F1F2689C400750356 /* ChromaShadeSlider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C376E51D5CF9400069D7A1 /* ChromaShadeSlider.swift */; };
1818
3503B8401F2689C400750356 /* UIColor+Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C376E61D5CF9400069D7A1 /* UIColor+Utilities.swift */; };
19+
3503B8641F27D2B100750356 /* ColorModeToggleButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3503B8631F27D2B100750356 /* ColorModeToggleButton.swift */; };
1920
35C376D11D5CF5300069D7A1 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C376D01D5CF5300069D7A1 /* AppDelegate.swift */; };
2021
35C376D31D5CF5300069D7A1 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35C376D21D5CF5300069D7A1 /* ViewController.swift */; };
2122
35C376D61D5CF5300069D7A1 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 35C376D41D5CF5300069D7A1 /* Main.storyboard */; };
@@ -60,6 +61,7 @@
6061
3503B82F1F2689BC00750356 /* ChromaColorPicker.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ChromaColorPicker.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6162
3503B8311F2689BC00750356 /* ChromaColorPicker.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ChromaColorPicker.h; sourceTree = "<group>"; };
6263
3503B8321F2689BC00750356 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
64+
3503B8631F27D2B100750356 /* ColorModeToggleButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ColorModeToggleButton.swift; path = ChromaColorPicker/ColorModeToggleButton.swift; sourceTree = SOURCE_ROOT; };
6365
35C376CD1D5CF5300069D7A1 /* ChromaColorPicker-Demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "ChromaColorPicker-Demo.app"; sourceTree = BUILT_PRODUCTS_DIR; };
6466
35C376D01D5CF5300069D7A1 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
6567
35C376D21D5CF5300069D7A1 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
@@ -158,6 +160,7 @@
158160
35C376E31D5CF9400069D7A1 /* ChromaHandle.swift */,
159161
35C376E21D5CF9400069D7A1 /* ChromaAddButton.swift */,
160162
35C376E51D5CF9400069D7A1 /* ChromaShadeSlider.swift */,
163+
3503B8631F27D2B100750356 /* ColorModeToggleButton.swift */,
161164
35C376E61D5CF9400069D7A1 /* UIColor+Utilities.swift */,
162165
);
163166
name = ChromaColorPicker;
@@ -390,6 +393,7 @@
390393
files = (
391394
3503B83C1F2689C400750356 /* ChromaColorPicker.swift in Sources */,
392395
3503B83D1F2689C400750356 /* ChromaHandle.swift in Sources */,
396+
3503B8641F27D2B100750356 /* ColorModeToggleButton.swift in Sources */,
393397
3503B83E1F2689C400750356 /* ChromaAddButton.swift in Sources */,
394398
3503B83F1F2689C400750356 /* ChromaShadeSlider.swift in Sources */,
395399
3503B8401F2689C400750356 /* UIColor+Utilities.swift in Sources */,
@@ -658,6 +662,7 @@
658662
3503B8391F2689BC00750356 /* Release */,
659663
);
660664
defaultConfigurationIsVisible = 0;
665+
defaultConfigurationName = Release;
661666
};
662667
35C376C81D5CF5300069D7A1 /* Build configuration list for PBXProject "ChromaColorPicker-Demo" */ = {
663668
isa = XCConfigurationList;

ChromaColorPicker-Demo.xcodeproj/xcuserdata/jcardasi.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<BreakpointProxy
77
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
88
<BreakpointContent
9-
shouldBeEnabled = "Yes"
9+
shouldBeEnabled = "No"
1010
ignoreCount = "0"
1111
continueAfterRunningActions = "No"
1212
filePath = "ChromaColorPicker/ChromaShadeSlider.swift"
@@ -22,7 +22,7 @@
2222
<BreakpointProxy
2323
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
2424
<BreakpointContent
25-
shouldBeEnabled = "Yes"
25+
shouldBeEnabled = "No"
2626
ignoreCount = "0"
2727
continueAfterRunningActions = "No"
2828
filePath = "ChromaColorPicker/ChromaShadeSlider.swift"
@@ -32,7 +32,7 @@
3232
startingLineNumber = "133"
3333
endingLineNumber = "133"
3434
landmarkName = "updateGradientTrack(for:)"
35-
landmarkType = "5">
35+
landmarkType = "7">
3636
</BreakpointContent>
3737
</BreakpointProxy>
3838
</Breakpoints>

ChromaColorPicker-Demo.xcodeproj/xcuserdata/jcardasi.xcuserdatad/xcschemes/xcschememanagement.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<key>ChromaColorPicker.xcscheme_^#shared#^_</key>
1313
<dict>
1414
<key>orderHint</key>
15-
<integer>3</integer>
15+
<integer>2</integer>
1616
</dict>
1717
<key>ChromaColorPickerTests.xcscheme_^#shared#^_</key>
1818
<dict>

ChromaColorPicker-Demo/Base.lproj/Main.storyboard

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11762" systemVersion="16E195" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
3+
<device id="retina4_7" orientation="portrait">
4+
<adaptation id="fullscreen"/>
5+
</device>
36
<dependencies>
47
<deployment identifier="iOS"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
9+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
610
</dependencies>
711
<scenes>
812
<!--View Controller-->
@@ -14,46 +18,31 @@
1418
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
1519
</layoutGuides>
1620
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
17-
<rect key="frame" x="0.0" y="0.0" width="414" height="736"/>
21+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
1822
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
1923
<subviews>
2024
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="ChromaColorPicker" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="guL-Cc-TeO">
21-
<rect key="frame" x="95" y="51" width="225" height="32"/>
25+
<rect key="frame" x="75" y="51" width="225" height="32"/>
2226
<constraints>
2327
<constraint firstAttribute="height" constant="32" id="PkF-mH-S41"/>
2428
<constraint firstAttribute="width" constant="225" id="XOI-CR-PLS"/>
2529
</constraints>
2630
<fontDescription key="fontDescription" type="system" pointSize="26"/>
27-
<color key="textColor" red="0.92549020051956177" green="0.93725490570068359" blue="0.94509804248809814" alpha="1" colorSpace="calibratedRGB"/>
31+
<color key="textColor" red="0.92549020051956177" green="0.93725490570068359" blue="0.94509804248809814" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
2832
<nil key="highlightedColor"/>
2933
</label>
30-
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="See ViewController for how ChromaColorPicker gets added here." textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="4" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bWG-XF-nzw">
31-
<rect key="frame" x="94" y="326" width="227" height="84"/>
32-
<constraints>
33-
<constraint firstAttribute="width" constant="227" id="925-2O-79o"/>
34-
<constraint firstAttribute="height" constant="84" id="xea-mR-yvJ"/>
35-
</constraints>
36-
<fontDescription key="fontDescription" type="system" pointSize="17"/>
37-
<color key="textColor" red="1" green="0.62745100259780884" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
38-
<nil key="highlightedColor"/>
39-
<userDefinedRuntimeAttributes>
40-
<userDefinedRuntimeAttribute type="number" keyPath="layer.opacity">
41-
<integer key="value" value="0"/>
42-
</userDefinedRuntimeAttribute>
43-
</userDefinedRuntimeAttributes>
44-
</label>
4534
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="© Jonathan Cardasis 2016" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="7z4-iq-l0n">
46-
<rect key="frame" x="0.0" y="715" width="414" height="21"/>
35+
<rect key="frame" x="0.0" y="646" width="375" height="21"/>
4736
<constraints>
4837
<constraint firstAttribute="height" constant="21" id="wA9-ws-4Xt"/>
4938
</constraints>
5039
<fontDescription key="fontDescription" type="system" pointSize="10"/>
51-
<color key="textColor" red="1" green="1" blue="1" alpha="0.25" colorSpace="calibratedRGB"/>
40+
<color key="textColor" red="1" green="1" blue="1" alpha="0.25" colorSpace="custom" customColorSpace="sRGB"/>
5241
<nil key="highlightedColor"/>
5342
</label>
5443
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="X0b-eI-A9U">
55-
<rect key="frame" x="182" y="644" width="50" height="50"/>
56-
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
44+
<rect key="frame" x="162.5" y="575" width="50" height="50"/>
45+
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
5746
<constraints>
5847
<constraint firstAttribute="height" constant="50" id="VaL-Xe-gHc"/>
5948
<constraint firstAttribute="width" constant="50" id="oSC-v5-nta"/>
@@ -65,8 +54,23 @@
6554
</userDefinedRuntimeAttribute>
6655
</userDefinedRuntimeAttributes>
6756
</view>
57+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="See ViewController for how ChromaColorPicker gets added here." textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="4" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bWG-XF-nzw">
58+
<rect key="frame" x="74" y="291.5" width="227" height="84"/>
59+
<constraints>
60+
<constraint firstAttribute="width" constant="227" id="925-2O-79o"/>
61+
<constraint firstAttribute="height" constant="84" id="xea-mR-yvJ"/>
62+
</constraints>
63+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
64+
<color key="textColor" red="1" green="0.62745100259780884" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
65+
<nil key="highlightedColor"/>
66+
<userDefinedRuntimeAttributes>
67+
<userDefinedRuntimeAttribute type="number" keyPath="layer.opacity">
68+
<integer key="value" value="0"/>
69+
</userDefinedRuntimeAttribute>
70+
</userDefinedRuntimeAttributes>
71+
</label>
6872
</subviews>
69-
<color key="backgroundColor" red="0.37647058823529411" green="0.49019607843137253" blue="0.54509803921568623" alpha="1" colorSpace="calibratedRGB"/>
73+
<color key="backgroundColor" red="0.37647058823529411" green="0.49019607843137253" blue="0.54509803921568623" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
7074
<constraints>
7175
<constraint firstItem="bWG-XF-nzw" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="2Xk-1O-6lX"/>
7276
<constraint firstItem="bWG-XF-nzw" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" id="Fpl-7y-W5w"/>
@@ -79,7 +83,6 @@
7983
<constraint firstItem="wfy-db-euE" firstAttribute="top" secondItem="X0b-eI-A9U" secondAttribute="bottom" constant="42" id="zjG-2C-dZg"/>
8084
</constraints>
8185
</view>
82-
<simulatedScreenMetrics key="simulatedDestinationMetrics" type="retina55"/>
8386
<connections>
8487
<outlet property="colorDisplayView" destination="X0b-eI-A9U" id="RdK-Y1-DrU"/>
8588
</connections>

ChromaColorPicker-Demo/ViewController.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,27 @@ class ViewController: UIViewController {
1717
override func viewDidLoad() {
1818
super.viewDidLoad()
1919

20-
//Calculate relative size and origin in bounds
20+
/* Calculate relative size and origin in bounds */
2121
let pickerSize = CGSize(width: view.bounds.width*0.8, height: view.bounds.width*0.8)
2222
let pickerOrigin = CGPoint(x: view.bounds.midX - pickerSize.width/2, y: view.bounds.midY - pickerSize.height/2)
2323

24-
//Create Color Picker
24+
/* Create Color Picker */
2525
colorPicker = ChromaColorPicker(frame: CGRect(origin: pickerOrigin, size: pickerSize))
2626
colorPicker.delegate = self
2727

28-
//Customize the view (optional)
28+
/* Customize the view (optional) */
2929
colorPicker.padding = 10
3030
colorPicker.stroke = 3 //stroke of the rainbow circle
3131
colorPicker.currentAngle = Float.pi
3232

33+
/* Customize for grayscale (optional) */
34+
colorPicker.supportsShadesOfGray = true // false by default
35+
//colorPicker.colorToggleButton.grayColorGradientLayer.colors = [UIColor.lightGray.cgColor, UIColor.gray.cgColor] // You can also override gradient colors
36+
37+
3338
colorPicker.hexLabel.textColor = UIColor.white
3439

35-
//Don't want an element like the shade slider? Just hide it:
40+
/* Don't want an element like the shade slider? Just hide it: */
3641
//colorPicker.shadeSlider.hidden = true
3742

3843
self.view.addSubview(colorPicker)

0 commit comments

Comments
 (0)