Skip to content

Instantly share code, notes, and snippets.

@C4Examples
Created July 25, 2012 16:33
Show Gist options
  • Save C4Examples/3177100 to your computer and use it in GitHub Desktop.
Save C4Examples/3177100 to your computer and use it in GitHub Desktop.
All Color Types
//
// C4WorkSpace.m
// Examples
//
// Created by Travis Kirton on 12-07-19.
// Copyright (c) 2012 POSTFL. All rights reserved.
//
#import "C4WorkSpace.h"
@interface C4WorkSpace ()
-(void)defaultColors;
-(void)C4Colors;
-(void)presetColors;
-(void)rgbColors;
-(void)hsbColors;
-(void)whiteColors;
-(void)systemColors;
-(void)alphaColors;
-(void)imagePatternColors;
@end
@implementation C4WorkSpace {
CGRect shapeFrame;
CGPoint shapeOrigin;
CGFloat whiteSpace;
C4Font *labelFont;
C4Label *label;
}
-(void)setup {
//define the height of individual shapes
CGFloat shapeHeight = self.canvas.height/10;
//calculate the white space between
whiteSpace = self.canvas.height - 9 * shapeHeight;
whiteSpace = whiteSpace/10;
shapeFrame = CGRectMake(0, 0, self.canvas.width - 2*whiteSpace, shapeHeight);
//create a font to use for the labels
labelFont = [C4Font fontWithName:@"ArialRoundedMTBold" size:20.0f];
//each type of color example is contained in its own method
[self defaultColors];
[self C4Colors];
[self presetColors];
[self rgbColors];
[self hsbColors];
[self whiteColors];
[self systemColors];
[self alphaColors];
[self imagePatternColors];
}
-(void)defaultColors {
C4Shape *rect = [C4Shape rect:shapeFrame];
shapeOrigin = CGPointMake(whiteSpace, whiteSpace);
rect.origin = shapeOrigin;
[self.canvas addShape:rect];
label = [C4Label labelWithText:@"Default Colors" font:labelFont];
label.center = rect.center;
[self.canvas addLabel:label];
}
-(void)C4Colors {
C4Shape *rect = [C4Shape rect:shapeFrame];
shapeOrigin.y += whiteSpace + rect.height;
rect.origin = shapeOrigin;
//There are 3 predefined colors in C4: C4BLUE, C4GREY, C4RED
rect.fillColor = C4RED;
rect.strokeColor = C4GREY;
[self.canvas addShape:rect];
label = [C4Label labelWithText:@"C4 Colors (from the logo)" font:labelFont];
label.center = rect.center;
[self.canvas addLabel:label];
}
-(void)presetColors {
C4Shape *rect = [C4Shape rect:shapeFrame];
shapeOrigin.y += whiteSpace + rect.height;
rect.origin = shapeOrigin;
//There are a series of predefined colors, see UIColor documentation for more
rect.fillColor = [UIColor orangeColor];
rect.strokeColor = [UIColor darkGrayColor];
[self.canvas addShape:rect];
label = [C4Label labelWithText:@"Predefined UIColors" font:labelFont];
label.center = rect.center;
[self.canvas addLabel:label];
}
-(void)rgbColors {
C4Shape *rect = [C4Shape rect:shapeFrame];
shapeOrigin.y += whiteSpace + rect.height;
rect.origin = shapeOrigin;
//You can set the RGB values with each component ranging from 0 .. 1.0 like this:
rect.fillColor = [UIColor colorWithRed:0.50 green:1.0 blue:0.0 alpha:1.0]; //lime (ish)
rect.strokeColor = [UIColor colorWithRed:0.50 green:0.0 blue:0.0 alpha:1.0]; //half red
[self.canvas addShape:rect];
label = [C4Label labelWithText:@"RGB Colors" font:labelFont];
label.center = rect.center;
[self.canvas addLabel:label];
}
-(void)hsbColors {
C4Shape *rect = [C4Shape rect:shapeFrame];
shapeOrigin.y += whiteSpace + rect.height;
rect.origin = shapeOrigin;
//You can set the HSB values with each component ranging from 0 .. 1.0 like this:
rect.fillColor = [UIColor colorWithHue:0.5 saturation:1.0 brightness:1.0 alpha:1.0];
rect.strokeColor = [UIColor colorWithHue:0.25 saturation:0.75 brightness:0.5 alpha:1.0];
[self.canvas addShape:rect];
label = [C4Label labelWithText:@"HSB Colors" font:labelFont];
label.center = rect.center;
[self.canvas addLabel:label];
}
-(void)whiteColors {
C4Shape *rect = [C4Shape rect:shapeFrame];
shapeOrigin.y += whiteSpace + rect.height;
rect.origin = shapeOrigin;
//You can set grayscale colors by defining them in the range of white:
rect.fillColor = [UIColor colorWithWhite:0.5 alpha:1.0];
rect.strokeColor = [UIColor colorWithWhite:0.33 alpha:1.0];
[self.canvas addShape:rect];
label = [C4Label labelWithText:@"White/Grayscale Colors" font:labelFont];
label.center = rect.center;
[self.canvas addLabel:label];
}
-(void)systemColors {
C4Shape *rect = [C4Shape rect:shapeFrame];
shapeOrigin.y += whiteSpace + rect.height;
rect.origin = shapeOrigin;
//There are a series of system colors, see UIColor documentation for more:
rect.fillColor = [UIColor scrollViewTexturedBackgroundColor]; //looks like a hatched color on my device
rect.strokeColor = [UIColor darkTextColor];
[self.canvas addShape:rect];
label = [C4Label labelWithText:@"System Colors" font:labelFont];
label.center = rect.center;
[self.canvas addLabel:label];
}
-(void)alphaColors {
C4Shape *rect = [C4Shape rect:shapeFrame];
shapeOrigin.y += whiteSpace + rect.height;
rect.origin = shapeOrigin;
//You can create transparent colors from UIColor objects
//This takes the default shape colors and makes them transparent
rect.fillColor = [rect.fillColor colorWithAlphaComponent:0.5];
rect.strokeColor = [rect.strokeColor colorWithAlphaComponent:0.5];
[self.canvas addShape:rect];
label = [C4Label labelWithText:@"Alpha Colors" font:labelFont];
label.center = rect.center;
[self.canvas addLabel:label];
}
-(void)imagePatternColors {
C4Shape *rect = [C4Shape rect:shapeFrame];
shapeOrigin.y += whiteSpace + rect.height;
rect.origin = shapeOrigin;
//You can create colors using images as well...
C4Image *fillPattern = [C4Image imageNamed:@"pyramid.png"];
rect.fillColor = [UIColor colorWithPatternImage:fillPattern.UIImage];
//Here we use a transparent fill pattern for the outline
C4Image *strokePattern = [C4Image imageNamed:@"pattern.png"];
rect.strokeColor = [UIColor colorWithPatternImage:strokePattern.UIImage];
[self.canvas addShape:rect];
label = [C4Label labelWithText:@"Pattern/Image Colors" font:labelFont];
label.center = rect.center;
[self.canvas addLabel:label];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment