Skip to content

Instantly share code, notes, and snippets.

@mmertsock
Last active December 20, 2015 00:49
Show Gist options
  • Save mmertsock/6045094 to your computer and use it in GitHub Desktop.
Save mmertsock/6045094 to your computer and use it in GitHub Desktop.
Simple UIColor testing tool. Create a new Single View Application in Xcode, with Storyboard and ARC enabled. Paste the code below into the .h and .m files for your view controller, and then right click your storyboard file, and choose Open As > Source Code. Then paste the XML below for the code of the storyboard. This should create a view with t…
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="2.0" toolsVersion="3084" systemVersion="12E55" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="2">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="2083"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="5">
<objects>
<viewController id="2" customClass="MMViewController" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="3">
<rect key="frame" x="0.0" y="20" width="320" height="548"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="0.5" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="yFS-QB-F6Y">
<connections>
<action selector="sliderChanged:" destination="2" eventType="valueChanged" id="yew-f8-nwA"/>
</connections>
</slider>
<slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="0.5" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="40d-xD-Wq3">
<connections>
<action selector="sliderChanged:" destination="2" eventType="valueChanged" id="Jxj-wA-NN9"/>
</connections>
</slider>
<slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="0.5" minValue="0.0" maxValue="1" translatesAutoresizingMaskIntoConstraints="NO" id="FHO-mu-hFE">
<connections>
<action selector="sliderChanged:" destination="2" eventType="valueChanged" id="FeZ-HJ-6jm"/>
</connections>
</slider>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="8mB-og-v4e">
<color key="backgroundColor" red="0.19958141446113586" green="0.42824909090995789" blue="0.42436566948890686" alpha="1" colorSpace="calibratedRGB"/>
</view>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Hue" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="71t-tp-mnn">
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Saturation" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="TCG-QK-LQY">
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="Brightness" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="KSL-Y2-nDu">
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="0.5" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="br2-24-Rhl">
<constraints>
<constraint firstAttribute="width" constant="63" id="lmv-1T-lHL"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="0.5" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="FJp-6G-Mqz">
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" text="0.5" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="6ja-K6-d5H">
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="6ja-K6-d5H" firstAttribute="baseline" secondItem="KSL-Y2-nDu" secondAttribute="baseline" type="default" id="07Z-bA-chV"/>
<constraint firstItem="40d-xD-Wq3" firstAttribute="top" secondItem="TCG-QK-LQY" secondAttribute="bottom" constant="8" symbolic="YES" type="default" id="2D9-ee-LDQ"/>
<constraint firstItem="yFS-QB-F6Y" firstAttribute="leading" secondItem="3" secondAttribute="leading" constant="20" symbolic="YES" type="default" id="4ZR-tb-Gqm"/>
<constraint firstItem="FHO-mu-hFE" firstAttribute="leading" secondItem="3" secondAttribute="leading" constant="20" symbolic="YES" type="default" id="53k-Ch-KZf"/>
<constraint firstItem="8mB-og-v4e" firstAttribute="trailing" secondItem="3" secondAttribute="trailing" type="default" id="DAF-WH-Hd7"/>
<constraint firstAttribute="trailing" secondItem="40d-xD-Wq3" secondAttribute="trailing" constant="20" symbolic="YES" type="default" id="DQC-qR-WA8"/>
<constraint firstItem="40d-xD-Wq3" firstAttribute="top" secondItem="3" secondAttribute="top" constant="410" id="Dm2-Ue-whi"/>
<constraint firstItem="FJp-6G-Mqz" firstAttribute="baseline" secondItem="TCG-QK-LQY" secondAttribute="baseline" type="default" id="H4e-UO-NjB"/>
<constraint firstItem="71t-tp-mnn" firstAttribute="centerX" secondItem="yFS-QB-F6Y" secondAttribute="centerX" type="default" id="MMh-q8-Q9h"/>
<constraint firstItem="8mB-og-v4e" firstAttribute="leading" secondItem="3" secondAttribute="leading" type="default" id="MVl-88-cik"/>
<constraint firstAttribute="bottom" secondItem="8mB-og-v4e" secondAttribute="bottom" constant="254" id="RJO-XP-etm"/>
<constraint firstItem="br2-24-Rhl" firstAttribute="baseline" secondItem="71t-tp-mnn" secondAttribute="baseline" type="default" id="UP0-mC-TKX"/>
<constraint firstItem="40d-xD-Wq3" firstAttribute="leading" secondItem="3" secondAttribute="leading" constant="20" symbolic="YES" type="default" id="VLL-1N-WYN"/>
<constraint firstAttribute="trailing" secondItem="FJp-6G-Mqz" secondAttribute="trailing" constant="20" symbolic="YES" type="default" id="X7a-yl-Ov8"/>
<constraint firstItem="6ja-K6-d5H" firstAttribute="leading" secondItem="FJp-6G-Mqz" secondAttribute="leading" type="default" id="YGw-e4-43O"/>
<constraint firstItem="TCG-QK-LQY" firstAttribute="top" secondItem="yFS-QB-F6Y" secondAttribute="bottom" constant="8" symbolic="YES" type="default" id="aKb-XB-3gh"/>
<constraint firstAttribute="trailing" secondItem="6ja-K6-d5H" secondAttribute="trailing" constant="20" symbolic="YES" type="default" id="eTL-uV-0X9"/>
<constraint firstItem="8mB-og-v4e" firstAttribute="top" secondItem="3" secondAttribute="top" type="default" id="iCP-TM-0jy"/>
<constraint firstItem="yFS-QB-F6Y" firstAttribute="top" secondItem="71t-tp-mnn" secondAttribute="bottom" constant="8" symbolic="YES" type="default" id="kuC-J7-9JE"/>
<constraint firstItem="FHO-mu-hFE" firstAttribute="top" secondItem="KSL-Y2-nDu" secondAttribute="bottom" constant="8" symbolic="YES" type="default" id="lKx-sG-RMa"/>
<constraint firstItem="FJp-6G-Mqz" firstAttribute="leading" secondItem="br2-24-Rhl" secondAttribute="leading" type="default" id="nmM-We-G5h"/>
<constraint firstAttribute="trailing" secondItem="yFS-QB-F6Y" secondAttribute="trailing" constant="20" symbolic="YES" type="default" id="pDm-fg-9z1"/>
<constraint firstItem="FHO-mu-hFE" firstAttribute="top" secondItem="3" secondAttribute="top" constant="472" id="qfp-IG-HZ6"/>
<constraint firstAttribute="trailing" secondItem="br2-24-Rhl" secondAttribute="trailing" constant="20" symbolic="YES" type="default" id="v1h-zg-w3r"/>
<constraint firstAttribute="trailing" secondItem="FHO-mu-hFE" secondAttribute="trailing" constant="20" symbolic="YES" type="default" id="v85-Vn-Hfy"/>
<constraint firstItem="TCG-QK-LQY" firstAttribute="centerX" secondItem="yFS-QB-F6Y" secondAttribute="centerX" type="default" id="yUV-Ok-pte"/>
<constraint firstItem="KSL-Y2-nDu" firstAttribute="leading" secondItem="TCG-QK-LQY" secondAttribute="leading" type="default" id="z4f-60-KS3"/>
</constraints>
</view>
<connections>
<outlet property="bLabel" destination="6ja-K6-d5H" id="WPP-ce-9lW"/>
<outlet property="bSlider" destination="FHO-mu-hFE" id="Ou0-a6-c65"/>
<outlet property="colorView" destination="8mB-og-v4e" id="3no-ZK-Vrd"/>
<outlet property="hLabel" destination="br2-24-Rhl" id="yAn-0G-YJl"/>
<outlet property="hSlider" destination="yFS-QB-F6Y" id="TbD-Rr-1bc"/>
<outlet property="sLabel" destination="FJp-6G-Mqz" id="sFt-ZV-eFW"/>
<outlet property="sSlider" destination="40d-xD-Wq3" id="Hok-kk-QaZ"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="4" sceneMemberID="firstResponder"/>
</objects>
</scene>
</scenes>
<classes>
<class className="MMViewController" superclassName="UIViewController">
<source key="sourceIdentifier" type="project" relativePath="./Classes/MMViewController.h"/>
<relationships>
<relationship kind="action" name="sliderChanged:"/>
<relationship kind="outlet" name="bLabel" candidateClass="UILabel"/>
<relationship kind="outlet" name="bSlider" candidateClass="UISlider"/>
<relationship kind="outlet" name="colorView" candidateClass="UIView"/>
<relationship kind="outlet" name="hLabel" candidateClass="UILabel"/>
<relationship kind="outlet" name="hSlider" candidateClass="UISlider"/>
<relationship kind="outlet" name="sLabel" candidateClass="UILabel"/>
<relationship kind="outlet" name="sSlider" candidateClass="UISlider"/>
</relationships>
</class>
<class className="NSLayoutConstraint" superclassName="NSObject">
<source key="sourceIdentifier" type="project" relativePath="./Classes/NSLayoutConstraint.h"/>
</class>
</classes>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination" type="retina4"/>
</simulatedMetricsContainer>
</document>
#import <UIKit/UIKit.h>
@interface MMViewController : UIViewController
@property (nonatomic, weak) IBOutlet UIView *colorView;
@property (nonatomic, weak) IBOutlet UILabel *hLabel;
@property (nonatomic, weak) IBOutlet UILabel *sLabel;
@property (nonatomic, weak) IBOutlet UILabel *bLabel;
@property (nonatomic, weak) IBOutlet UISlider *hSlider;
@property (nonatomic, weak) IBOutlet UISlider *sSlider;
@property (nonatomic, weak) IBOutlet UISlider *bSlider;
- (IBAction)sliderChanged:(id)sender;
@end
#import "MMViewController.h"
@interface MMViewController ()
@property (nonatomic) NSNumberFormatter *formatter;
@end
@implementation MMViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.formatter = [NSNumberFormatter new];
self.formatter.allowsFloats = YES;
self.formatter.numberStyle = NSNumberFormatterDecimalStyle;
self.formatter.maximumFractionDigits = 3;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)sliderChanged:(id)sender {
CGFloat hue = self.hSlider.value;
CGFloat sat = self.sSlider.value;
CGFloat brt = self.bSlider.value;
self.hLabel.text = [self.formatter stringFromNumber:@(hue)];
self.sLabel.text = [self.formatter stringFromNumber:@(sat)];
self.bLabel.text = [self.formatter stringFromNumber:@(brt)];
UIColor *color = [UIColor colorWithHue:hue saturation:sat brightness:brt alpha:1];
self.colorView.backgroundColor = color;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment