diff --git a/Demo.xcodeproj/project.pbxproj b/Demo.xcodeproj/project.pbxproj index 89b5f5b..284f9b0 100644 --- a/Demo.xcodeproj/project.pbxproj +++ b/Demo.xcodeproj/project.pbxproj @@ -7,7 +7,10 @@ objects = { /* Begin PBXBuildFile section */ - 273E9EE865984F44A8AF2A9D /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D2957D8BD1FB4630AD6F922F /* libPods.a */; }; + 0D0852F651BA48A6A2690509 /* libPods-Demo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E57629B1A00D4050BE057987 /* libPods-Demo.a */; }; + 3C205ADD19083CC600B3C2B4 /* EDColoriOS7ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C205ADC19083CC600B3C2B4 /* EDColoriOS7ViewController.m */; }; + 3C205AE019083E5F00B3C2B4 /* EDColoriOS7ViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3C205ADF19083E5F00B3C2B4 /* EDColoriOS7ViewController.xib */; }; + 3C205AE41908448B00B3C2B4 /* EDColoriOS7ViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3C205AE31908448B00B3C2B4 /* EDColoriOS7ViewCell.xib */; }; 3C562C6618DC8B4500DE3F38 /* Images in Resources */ = {isa = PBXBuildFile; fileRef = 3C562C6518DC8B4500DE3F38 /* Images */; }; 3CB0E6D718C8B9E2009CE8DB /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3CB0E6D618C8B9E2009CE8DB /* Foundation.framework */; }; 3CB0E6D918C8B9E2009CE8DB /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3CB0E6D818C8B9E2009CE8DB /* CoreGraphics.framework */; }; @@ -24,10 +27,13 @@ 3CE9EC0D18FC602D0034ADA7 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CE9EC0C18FC602D0034ADA7 /* main.m */; }; 3CE9EC2318FC64850034ADA7 /* EDFirstViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3CE9EC2218FC64850034ADA7 /* EDFirstViewController.xib */; }; 3CE9EC2518FC648D0034ADA7 /* EDSecondViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3CE9EC2418FC648D0034ADA7 /* EDSecondViewController.xib */; }; - F4AB3EC2A2444AD19798863E /* libPods-Demo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C66239C348A64C5382E2FEFE /* libPods-Demo.a */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 3C205ADB19083CC600B3C2B4 /* EDColoriOS7ViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EDColoriOS7ViewController.h; sourceTree = ""; }; + 3C205ADC19083CC600B3C2B4 /* EDColoriOS7ViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EDColoriOS7ViewController.m; sourceTree = ""; }; + 3C205ADF19083E5F00B3C2B4 /* EDColoriOS7ViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = EDColoriOS7ViewController.xib; sourceTree = ""; }; + 3C205AE31908448B00B3C2B4 /* EDColoriOS7ViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = EDColoriOS7ViewCell.xib; sourceTree = ""; }; 3C562C6518DC8B4500DE3F38 /* Images */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Images; sourceTree = ""; }; 3CB0E6D318C8B9E2009CE8DB /* Demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Demo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 3CB0E6D618C8B9E2009CE8DB /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; @@ -53,11 +59,7 @@ 3CE9EC0C18FC602D0034ADA7 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 3CE9EC2218FC64850034ADA7 /* EDFirstViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = EDFirstViewController.xib; sourceTree = ""; }; 3CE9EC2418FC648D0034ADA7 /* EDSecondViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = EDSecondViewController.xib; sourceTree = ""; }; - 98DB4ADA533041DD9D9E7647 /* libPods-IntegrationTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-IntegrationTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; - B407DD3D5B084B98A0022A4D /* libPods-IntegrationTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-IntegrationTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; - BD0E280B71AE47E499695C40 /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = ""; }; - C66239C348A64C5382E2FEFE /* libPods-Demo.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Demo.a"; sourceTree = BUILT_PRODUCTS_DIR; }; - D2957D8BD1FB4630AD6F922F /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; }; + E57629B1A00D4050BE057987 /* libPods-Demo.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Demo.a"; sourceTree = BUILT_PRODUCTS_DIR; }; FE4DCA04C7CC4E32A9AEA10B /* Pods-Demo.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Demo.xcconfig"; path = "Pods/Pods-Demo.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -69,8 +71,7 @@ 3CB0E6D918C8B9E2009CE8DB /* CoreGraphics.framework in Frameworks */, 3CB0E6DB18C8B9E2009CE8DB /* UIKit.framework in Frameworks */, 3CB0E6D718C8B9E2009CE8DB /* Foundation.framework in Frameworks */, - 273E9EE865984F44A8AF2A9D /* libPods.a in Frameworks */, - F4AB3EC2A2444AD19798863E /* libPods-Demo.a in Frameworks */, + 0D0852F651BA48A6A2690509 /* libPods-Demo.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -83,7 +84,6 @@ 3CB0E6DC18C8B9E2009CE8DB /* Demo */, 3CB0E6D518C8B9E2009CE8DB /* Frameworks */, 3CB0E6D418C8B9E2009CE8DB /* Products */, - BD0E280B71AE47E499695C40 /* Pods.xcconfig */, FE4DCA04C7CC4E32A9AEA10B /* Pods-Demo.xcconfig */, ); sourceTree = ""; @@ -103,10 +103,7 @@ 3CB0E6D818C8B9E2009CE8DB /* CoreGraphics.framework */, 3CB0E6DA18C8B9E2009CE8DB /* UIKit.framework */, 3CB0E6F518C8B9E2009CE8DB /* XCTest.framework */, - D2957D8BD1FB4630AD6F922F /* libPods.a */, - 98DB4ADA533041DD9D9E7647 /* libPods-IntegrationTests.a */, - C66239C348A64C5382E2FEFE /* libPods-Demo.a */, - B407DD3D5B084B98A0022A4D /* libPods-IntegrationTests.a */, + E57629B1A00D4050BE057987 /* libPods-Demo.a */, ); name = Frameworks; sourceTree = ""; @@ -114,6 +111,7 @@ 3CB0E6DC18C8B9E2009CE8DB /* Demo */ = { isa = PBXGroup; children = ( + 3C205AE31908448B00B3C2B4 /* EDColoriOS7ViewCell.xib */, 3CE9EC2418FC648D0034ADA7 /* EDSecondViewController.xib */, 3CE9EC2218FC64850034ADA7 /* EDFirstViewController.xib */, 3CE9EC0C18FC602D0034ADA7 /* main.m */, @@ -132,6 +130,9 @@ 3CB0E70E18C8BB08009CE8DB /* EDAppDelegate.m */, 3CB0E6EE18C8B9E2009CE8DB /* Images.xcassets */, 3CB0E6DD18C8B9E2009CE8DB /* Supporting Files */, + 3C205ADB19083CC600B3C2B4 /* EDColoriOS7ViewController.h */, + 3C205ADC19083CC600B3C2B4 /* EDColoriOS7ViewController.m */, + 3C205ADF19083E5F00B3C2B4 /* EDColoriOS7ViewController.xib */, ); path = Demo; sourceTree = ""; @@ -203,11 +204,13 @@ files = ( 3CB0E6EF18C8B9E2009CE8DB /* Images.xcassets in Resources */, 3CE9EC2518FC648D0034ADA7 /* EDSecondViewController.xib in Resources */, + 3C205AE41908448B00B3C2B4 /* EDColoriOS7ViewCell.xib in Resources */, 3C562C6618DC8B4500DE3F38 /* Images in Resources */, 3CE9EC2318FC64850034ADA7 /* EDFirstViewController.xib in Resources */, 3CB0E6E118C8B9E2009CE8DB /* InfoPlist.strings in Resources */, 3CE9EC0B18FC5FB80034ADA7 /* EDThirdViewController.xib in Resources */, 3CE9EC0818FC5FB80034ADA7 /* EDFourthViewController.xib in Resources */, + 3C205AE019083E5F00B3C2B4 /* EDColoriOS7ViewController.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -252,6 +255,7 @@ buildActionMask = 2147483647; files = ( 3CE9EC0918FC5FB80034ADA7 /* EDSecondViewController.m in Sources */, + 3C205ADD19083CC600B3C2B4 /* EDColoriOS7ViewController.m in Sources */, 3CE9EC0618FC5FB80034ADA7 /* EDFirstViewController.m in Sources */, 3CB0E71C18C8BB08009CE8DB /* EDAppDelegate.m in Sources */, 3CE9EC0718FC5FB80034ADA7 /* EDFourthViewController.m in Sources */, diff --git a/Demo/EDAppDelegate.m b/Demo/EDAppDelegate.m index 7dee2c6..8d965fa 100644 --- a/Demo/EDAppDelegate.m +++ b/Demo/EDAppDelegate.m @@ -12,6 +12,7 @@ #import "EDSecondViewController.h" #import "EDThirdViewController.h" #import "EDFourthViewController.h" +#import "EDColoriOS7ViewController.h" @implementation EDAppDelegate @@ -23,8 +24,9 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( UIViewController *viewController2 = [[EDSecondViewController alloc] initWithNibName:@"EDSecondViewController" bundle:nil]; UIViewController *viewController3 = [[EDThirdViewController alloc] initWithNibName:@"EDThirdViewController" bundle:nil]; UIViewController *viewController4 = [[EDFourthViewController alloc] initWithNibName:@"EDFourthViewController" bundle:nil]; + UIViewController *viewControlleriOS7Colors = [[EDColoriOS7ViewController alloc] initWithNibName:@"EDColoriOS7ViewController" bundle:nil]; self.tabBarController = [[UITabBarController alloc] init]; - self.tabBarController.viewControllers = @[viewController1, viewController2, viewController3, viewController4]; + self.tabBarController.viewControllers = @[viewController1, viewController2, viewController3, viewController4, viewControlleriOS7Colors]; self.window.rootViewController = self.tabBarController; [self.window makeKeyAndVisible]; return YES; diff --git a/Demo/EDColoriOS7ViewCell.xib b/Demo/EDColoriOS7ViewCell.xib new file mode 100644 index 0000000..a968c66 --- /dev/null +++ b/Demo/EDColoriOS7ViewCell.xib @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Demo/EDColoriOS7ViewController.h b/Demo/EDColoriOS7ViewController.h new file mode 100644 index 0000000..35a9eda --- /dev/null +++ b/Demo/EDColoriOS7ViewController.h @@ -0,0 +1,13 @@ +// +// EDColoriOS7iOS7ViewController.h +// Demo +// +// Created by Daniel Doubrovkine on 4/23/14. +// Copyright (c) 2014 Andrew Sliwinski. All rights reserved. +// + +#import + +@interface EDColoriOS7ViewController : UIViewController +@property (nonatomic, strong) IBOutlet UICollectionView *collectionView; +@end diff --git a/Demo/EDColoriOS7ViewController.m b/Demo/EDColoriOS7ViewController.m new file mode 100644 index 0000000..1076490 --- /dev/null +++ b/Demo/EDColoriOS7ViewController.m @@ -0,0 +1,137 @@ +// +// EDColoriOS7ViewController.m +// Demo +// +// Created by Daniel Doubrovkine on 4/23/14. +// Copyright (c) 2014 Andrew Sliwinski. All rights reserved. +// + +#import "EDColoriOS7ViewController.h" +#import +#import + +@interface EDColoriOS7ViewController () +@property(nonatomic, strong, readonly) NSArray *colors; +@end + +@implementation EDColoriOS7ViewController + +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil +{ + self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; + if (self) { + self.title = @"iOS7"; + NSMutableArray *colors = [[NSMutableArray alloc] init]; + [colors addObjectsFromArray:[UIColor iOS7Colors]]; + [colors addObjectsFromArray:[UIColor iOS7GradientPairs]]; + _colors = colors; + } + return self; +} + +- (void)viewDidLoad +{ + UINib *cellNib = [UINib nibWithNibName:@"EDColoriOS7ViewCell" bundle:nil]; + [self.collectionView registerNib:cellNib forCellWithReuseIdentifier:@"EDColoriOS7ViewCell"]; + + UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; + [flowLayout setItemSize:CGSizeMake(160, 160)]; + [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical]; + [self.collectionView setCollectionViewLayout:flowLayout]; +} + +- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView +{ + return 1; +} + +- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section +{ + return self.colors.count; +} + +- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath +{ + static NSString *cellIdentifier = @"EDColoriOS7ViewCell"; + UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath]; + id colorOrColors = self.colors[indexPath.row]; + UIColor *fromColor; + UIColor *toColor; + NSString *title; + if ([[colorOrColors class] isSubclassOfClass:[NSArray class]]) { + fromColor = (id) [(NSArray *)colorOrColors firstObject]; + toColor = (id) [(NSArray *)colorOrColors lastObject]; + title = [NSString stringWithFormat:@"0x%x - 0x%x", (unsigned int)fromColor.hexValue, (unsigned int)toColor.hexValue]; + } else { + fromColor = toColor = (UIColor *) colorOrColors; + title = [NSString stringWithFormat:@"0x%x", (unsigned int) fromColor.hexValue]; + } + + UIImageView *imageView = (UIImageView *)[cell viewWithTag:200]; + [imageView setImage:[self drawGradientImageFromColor:fromColor toColor:toColor imageSize:imageView.frame.size]]; + UILabel *titleLabel = (UILabel *)[cell viewWithTag:100]; + [titleLabel setText:title]; + + return cell; +} + +- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section +{ + return 0; +} + +- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section +{ + return 0; +} + +- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section +{ + return UIEdgeInsetsMake(0, 0, 0, 0); +} + +// http://carlos-blog.logdown.com/posts/2013/09/14/ios-uiimage-with-gradient-color +- (UIImage *)drawGradientImageFromColor:(UIColor *)beginColor toColor:(UIColor *)endColor imageSize:(CGSize)imageSize +{ + // set sideline width + CGFloat lineWidth = 3.0f; + // set a canvas, and use the imageSize + UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0); + // set RGB color space + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + // set draw context + CGContextRef context = UIGraphicsGetCurrentContext(); + // set color to array + NSArray *gradientColors = [NSArray arrayWithObjects:(id) beginColor.CGColor, (id) endColor.CGColor, nil]; + // set range 0~1 + // two value, cause two color + // if more color, add more value + CGFloat gradientLocation[] = { 0, 1 }; + // set gradient info + CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef)gradientColors, gradientLocation); + // set rectangle path for bezier path + UIBezierPath * bezierPath = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, imageSize.width, imageSize.height)]; + CGContextSaveGState(context); + [bezierPath addClip]; + // set gradient start point and end point + CGPoint beginPoint = CGPointMake(imageSize.width / 2, 0); + CGPoint endPoint = CGPointMake(imageSize.width / 2, imageSize.height); + // add position to linear gradient + CGContextDrawLinearGradient(context, gradient, beginPoint, endPoint, 0); + // set sideline info + CGContextSetStrokeColorWithColor(context, [[UIColor blackColor] CGColor]); + // draw sideline + [bezierPath setLineWidth:lineWidth]; + // fill gradient color + [bezierPath stroke]; + CGContextRestoreGState(context); + // output context to image + UIImage * image = UIGraphicsGetImageFromCurrentImageContext(); + // context end and release + UIGraphicsEndImageContext(); + CGColorSpaceRelease(colorSpace); + CGGradientRelease(gradient); + return image; +} + +@end diff --git a/Demo/EDColoriOS7ViewController.xib b/Demo/EDColoriOS7ViewController.xib new file mode 100644 index 0000000..5108ad4 --- /dev/null +++ b/Demo/EDColoriOS7ViewController.xib @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Demo/EDFirstViewController.xib b/Demo/EDFirstViewController.xib index dd6aaed..e869e14 100644 --- a/Demo/EDFirstViewController.xib +++ b/Demo/EDFirstViewController.xib @@ -1,269 +1,54 @@ - - - - 1296 - 11E53 - 2549 - 1138.47 - 569.00 - - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - 1498 - - - IBProxyObject - IBUIImageView - IBUILabel - IBUITextField - IBUIView - - - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - - - PluginDependencyRecalculationVersion - - - - - IBFilesOwner - IBCocoaTouchFramework - - - IBFirstResponder - IBCocoaTouchFramework - - - - 274 - - - - 292 - {{20, 24}, {85, 21}} - - - _NS:9 - NO - YES - 7 - NO - IBCocoaTouchFramework - Hex String: - - 1 - MCAwIDAAA - - - 0 - 10 - - 1 - 17 - - - Helvetica - 17 - 16 - - - - - 292 - {{113, 20}, {187, 31}} - - - _NS:9 - NO - YES - IBCocoaTouchFramework - 0 - #00ffffcc - 3 - - 3 - MAA - - 2 - - - YES - 17 - - 9 - YES - IBCocoaTouchFramework - - 3 - - 1 - 14 - - - Helvetica - 14 - 16 - - - - - 274 - {{0, 69}, {320, 342}} - - - _NS:9 - NO - IBCocoaTouchFramework - - NSImage - background@2x.png - - - - - 292 - {{0, 69}, {320, 342}} - - _NS:9 - - 3 - MQA - - - IBCocoaTouchFramework - - - {{0, 20}, {320, 411}} - - - - 3 - MQA - - - - IBCocoaTouchFramework - - - - - - - view - - - - 3 - - - - input - - - - 11 - - - - swatch - - - - 12 - - - - update: - - - 20 - - 20 - - - - - - 0 - - - - - - 1 - - - - - - - - - - - -1 - - - File's Owner - - - -2 - - - - - 8 - - - - - 9 - - - - - 10 - - - - - - 17 - - - - - - - EDFirstViewController - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - UIResponder - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - com.apple.InterfaceBuilder.IBCocoaTouchPlugin - - - - - - 20 - - - 0 - IBCocoaTouchFramework - - com.apple.InterfaceBuilder.CocoaTouchPlugin.iPhoneOS - - - YES - 3 - - background@2x.png - {640, 684} - - 1498 - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Demo/Images/example_ios7.png b/Demo/Images/example_ios7.png new file mode 100644 index 0000000..2a56521 Binary files /dev/null and b/Demo/Images/example_ios7.png differ diff --git a/EDColor/EDColor.h b/EDColor/EDColor.h index d678320..543a2c4 100644 --- a/EDColor/EDColor.h +++ b/EDColor/EDColor.h @@ -10,4 +10,5 @@ #import "UIColor+HSB.h" #import "UIColor+HSL.h" #import "UIColor+Crayola.h" -#import "UIColor+CIELAB.h" \ No newline at end of file +#import "UIColor+CIELAB.h" +#import "UIColor+iOS7.h" diff --git a/EDColor/UIColor+iOS7.h b/EDColor/UIColor+iOS7.h new file mode 100644 index 0000000..be048cf --- /dev/null +++ b/EDColor/UIColor+iOS7.h @@ -0,0 +1,48 @@ +// +// UIColor+iOS7.h +// color +// +// Created by D. Patrick Caldwell on 2/7/14. +// Added to EDColor by Daniel Doubrovkine on 4/23/14. +// Copyright (c) 2014 D. Patrick Caldwell. All rights reserved. +// + +#import + +@interface UIColor (iOS7) + +#define gradientPair(name) \ ++ (instancetype)iOS7##name##GradientStartColor; \ ++ (instancetype)iOS7##name##GradientEndColor; \ ++ (NSArray *)iOS7##name##Gradient; + ++ (instancetype)iOS7redColor; ++ (instancetype)iOS7orangeColor; ++ (instancetype)iOS7yellowColor; ++ (instancetype)iOS7greenColor; ++ (instancetype)iOS7tealColor; ++ (instancetype)iOS7blueColor; ++ (instancetype)iOS7violetColor; ++ (instancetype)iOS7magentaColor; ++ (instancetype)iOS7darkGreyColor; ++ (instancetype)iOS7lightGreyColor; ++ (instancetype)iOS7charcoalColor; + ++ (NSArray *)iOS7Colors; ++ (NSArray *)iOS7GradientPairs; + +gradientPair(red) +gradientPair(orange) +gradientPair(yellow) +gradientPair(green) +gradientPair(teal) +gradientPair(blue) +gradientPair(violet) +gradientPair(magenta) +gradientPair(charcoal) +gradientPair(silver) + +#undef gradientPair + +@end + diff --git a/EDColor/UIColor+iOS7.m b/EDColor/UIColor+iOS7.m new file mode 100644 index 0000000..343de59 --- /dev/null +++ b/EDColor/UIColor+iOS7.m @@ -0,0 +1,79 @@ +// +// UIColor+iOS7.h +// color +// +// Created by D. Patrick Caldwell on 2/7/14. +// Added to EDColor by Daniel Doubrovkine on 4/23/14. +// Copyright (c) 2014 D. Patrick Caldwell. All rights reserved. +// + +#import "UIColor+iOS7.h" +#import "UIColor+Hex.h" + +@implementation UIColor (iOS7) + +#define gradientPair(name, start, end) \ ++ (instancetype)iOS7##name##GradientStartColor { return [UIColor colorWithHex:start]; } \ ++ (instancetype)iOS7##name##GradientEndColor { return [UIColor colorWithHex:end]; } \ ++ (NSArray *)iOS7##name##Gradient { return @[(id)UIColor.iOS7##name##GradientStartColor, (id)UIColor.iOS7##name##GradientEndColor]; } + ++ (NSArray *)iOS7GradientPairs +{ + return @[ + [self.class iOS7redGradient], + [self.class iOS7orangeGradient], + [self.class iOS7yellowGradient], + [self.class iOS7greenGradient], + [self.class iOS7tealGradient], + [self.class iOS7blueGradient], + [self.class iOS7violetGradient], + [self.class iOS7magentaGradient], + [self.class iOS7charcoalGradient], + [self.class iOS7silverGradient], + ]; +} + ++ (NSArray *)iOS7Colors +{ + return @[ + [self.class iOS7redColor], + [self.class iOS7orangeColor], + [self.class iOS7yellowColor], + [self.class iOS7greenColor], + [self.class iOS7tealColor], + [self.class iOS7blueColor], + [self.class iOS7violetColor], + [self.class iOS7magentaColor], + [self.class iOS7darkGreyColor], + [self.class iOS7lightGreyColor], + [self.class iOS7charcoalColor], + ]; +} + ++ (instancetype)iOS7redColor { return [UIColor colorWithHex:0xFF3B30]; } ++ (instancetype)iOS7orangeColor { return [UIColor colorWithHex:0xFF9500]; } ++ (instancetype)iOS7yellowColor { return [UIColor colorWithHex:0xFFCC00]; } ++ (instancetype)iOS7greenColor { return [UIColor colorWithHex:0x4CD964]; } ++ (instancetype)iOS7tealColor { return [UIColor colorWithHex:0x34AADC]; } ++ (instancetype)iOS7blueColor { return [UIColor colorWithHex:0x007AFF]; } ++ (instancetype)iOS7violetColor { return [UIColor colorWithHex:0x5856D6]; } ++ (instancetype)iOS7magentaColor { return [UIColor colorWithHex:0xFF2D55]; } ++ (instancetype)iOS7darkGreyColor { return [UIColor colorWithHex:0x8E8E93]; } ++ (instancetype)iOS7lightGreyColor { return [UIColor colorWithHex:0xC7C7CC]; } ++ (instancetype)iOS7charcoalColor { return [UIColor colorWithHex:0x4A4A4A]; } + +gradientPair(red, 0xFF5E3A, 0xFF2A68) +gradientPair(orange, 0xFF9500, 0xFF5E3A) +gradientPair(yellow, 0xFFDB4C, 0xFFCD02) +gradientPair(green, 0x87FC70, 0x0BD318) +gradientPair(teal, 0x52EDC7, 0x5AC8FB) +gradientPair(blue, 0x1AD6FD, 0x1D62F0) +gradientPair(violet, 0xC644FC, 0x5856D6) +gradientPair(magenta, 0xEF4DB6, 0xC643FC) +gradientPair(charcoal, 0x4A4A4A, 0x2B2B2B) +gradientPair(silver, 0xDBDDDE, 0x898C90) + +@end + +#undef gradientPair +#undef colorFromInteger diff --git a/README.md b/README.md index 65caee7..511bed3 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,18 @@ UIColor *rorange = [UIColor colorWithCrayola:@"Orange Red"]; ``` ![](https://raw.github.com/thisandagain/color/master/Demo/Images/example_crayola.png) + +### UIColor+iOS7 +Some of the iOS7 colors from [ios7colors.com](http://ios7colors.com/). +```objective-c +UIColor *yellow = [UIColor iOS7yellowColor]; + +UIColor *greenGradientStart = [UIColor iOS7greenGradientStartColor]; +UIColor *greenGradientEnd = [UIColor iOS7greenGradientEndColor]; +``` +![](Demo/Images/example_ios7.png) + + --- ### Contributing diff --git a/Tests.xcodeproj/project.pbxproj b/Tests.xcodeproj/project.pbxproj index 56afa9d..e5b33c2 100644 --- a/Tests.xcodeproj/project.pbxproj +++ b/Tests.xcodeproj/project.pbxproj @@ -8,6 +8,8 @@ /* Begin PBXBuildFile section */ 3C12144818FC678B003CDC74 /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3C12144718FC678B003CDC74 /* SenTestingKit.framework */; }; + 3C205AD519083BE100B3C2B4 /* EDColoriOS7Test.h in Sources */ = {isa = PBXBuildFile; fileRef = 3C205AD419083BE100B3C2B4 /* EDColoriOS7Test.h */; }; + 3C205ADA19083C8100B3C2B4 /* EDColoriOS7Test.m in Sources */ = {isa = PBXBuildFile; fileRef = 3C205AD919083C8100B3C2B4 /* EDColoriOS7Test.m */; }; 3CE9EC3318FC65650034ADA7 /* EDColorCIELABBoundsTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CE9EC2818FC65650034ADA7 /* EDColorCIELABBoundsTest.m */; }; 3CE9EC3418FC65650034ADA7 /* EDColorCIELABTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CE9EC2A18FC65650034ADA7 /* EDColorCIELABTest.m */; }; 3CE9EC3518FC65650034ADA7 /* EDColorCrayolaTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 3CE9EC2C18FC65650034ADA7 /* EDColorCrayolaTest.m */; }; @@ -20,6 +22,9 @@ /* Begin PBXFileReference section */ 3C12144718FC678B003CDC74 /* SenTestingKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SenTestingKit.framework; path = Library/Frameworks/SenTestingKit.framework; sourceTree = DEVELOPER_DIR; }; + 3C205AD419083BE100B3C2B4 /* EDColoriOS7Test.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EDColoriOS7Test.h; sourceTree = ""; }; + 3C205AD919083C8100B3C2B4 /* EDColoriOS7Test.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EDColoriOS7Test.m; sourceTree = ""; }; + 3C205ADE19083DAA00B3C2B4 /* Tests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Tests.octest; sourceTree = BUILT_PRODUCTS_DIR; }; 3CE9EC2718FC65650034ADA7 /* EDColorCIELABBoundsTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EDColorCIELABBoundsTest.h; sourceTree = ""; }; 3CE9EC2818FC65650034ADA7 /* EDColorCIELABBoundsTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EDColorCIELABBoundsTest.m; sourceTree = ""; }; 3CE9EC2918FC65650034ADA7 /* EDColorCIELABTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EDColorCIELABTest.h; sourceTree = ""; }; @@ -33,13 +38,11 @@ 3CE9EC3118FC65650034ADA7 /* EDColorHSLTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EDColorHSLTest.h; sourceTree = ""; }; 3CE9EC3218FC65650034ADA7 /* EDColorHSLTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EDColorHSLTest.m; sourceTree = ""; }; 3CE9EC3918FC65860034ADA7 /* Macros.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Macros.h; sourceTree = ""; }; - 3CFB65BC18E200F600E00693 /* Tests.octest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; name = Tests.octest; path = "/Users/dblock/source/color/dblock/build/Debug-iphoneos/Tests.octest"; sourceTree = ""; }; 3CFB65C718E200F600E00693 /* Tests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Tests-Info.plist"; sourceTree = ""; }; 3CFB65C918E200F600E00693 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 3CFB65CD18E200F600E00693 /* Tests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Tests-Prefix.pch"; sourceTree = ""; }; 5917ADED41E84FE1A1C6D6C5 /* libPods-Tests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Tests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 937E2C394A8B4F15B1455C01 /* Pods-Tests.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Tests.xcconfig"; path = "Pods/Pods-Tests.xcconfig"; sourceTree = ""; }; - A64D71883054425489005487 /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -60,8 +63,8 @@ children = ( 3CFB65C518E200F600E00693 /* Tests */, 3CFB65BE18E200F600E00693 /* Frameworks */, - A64D71883054425489005487 /* Pods.xcconfig */, 937E2C394A8B4F15B1455C01 /* Pods-Tests.xcconfig */, + 3C205ADE19083DAA00B3C2B4 /* Tests.octest */, ); sourceTree = ""; }; @@ -77,6 +80,7 @@ 3CFB65C518E200F600E00693 /* Tests */ = { isa = PBXGroup; children = ( + 3C205AD919083C8100B3C2B4 /* EDColoriOS7Test.m */, 3CE9EC2718FC65650034ADA7 /* EDColorCIELABBoundsTest.h */, 3CE9EC2818FC65650034ADA7 /* EDColorCIELABBoundsTest.m */, 3CE9EC2918FC65650034ADA7 /* EDColorCIELABTest.h */, @@ -90,6 +94,7 @@ 3CE9EC3118FC65650034ADA7 /* EDColorHSLTest.h */, 3CE9EC3218FC65650034ADA7 /* EDColorHSLTest.m */, 3CFB65C618E200F600E00693 /* Supporting Files */, + 3C205AD419083BE100B3C2B4 /* EDColoriOS7Test.h */, ); path = Tests; sourceTree = ""; @@ -124,7 +129,7 @@ ); name = Tests; productName = Tests; - productReference = 3CFB65BC18E200F600E00693 /* Tests.octest */; + productReference = 3C205ADE19083DAA00B3C2B4 /* Tests.octest */; productType = "com.apple.product-type.bundle.unit-test"; }; /* End PBXNativeTarget section */ @@ -203,9 +208,11 @@ files = ( 3CE9EC3618FC65650034ADA7 /* EDColorHexTest.m in Sources */, 3CE9EC3418FC65650034ADA7 /* EDColorCIELABTest.m in Sources */, + 3C205AD519083BE100B3C2B4 /* EDColoriOS7Test.h in Sources */, 3CE9EC3318FC65650034ADA7 /* EDColorCIELABBoundsTest.m in Sources */, 3CE9EC3718FC65650034ADA7 /* EDColorHSBTest.m in Sources */, 3CE9EC3818FC65650034ADA7 /* EDColorHSLTest.m in Sources */, + 3C205ADA19083C8100B3C2B4 /* EDColoriOS7Test.m in Sources */, 3CE9EC3518FC65650034ADA7 /* EDColorCrayolaTest.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Tests/EDColoriOS7Test.h b/Tests/EDColoriOS7Test.h new file mode 100644 index 0000000..803ce7d --- /dev/null +++ b/Tests/EDColoriOS7Test.h @@ -0,0 +1,13 @@ +// +// EDColoriOS7Test.h +// color +// +// Created by Daniel Doubrovkine on 4/23/14. +// Copyright (c) 2012 Andrew Sliwinski. All rights reserved. +// + +#import + +@interface EDColoriOS7Test : SenTestCase + +@end diff --git a/Tests/EDColoriOS7Test.m b/Tests/EDColoriOS7Test.m new file mode 100644 index 0000000..7e8f30e --- /dev/null +++ b/Tests/EDColoriOS7Test.m @@ -0,0 +1,44 @@ +// +// EDColoriOS7Test.m +// color +// +// Created by Daniel Doubrovkine on 4/23/14. +// Copyright (c) 2012 Andrew Sliwinski. All rights reserved. +// + +#import "EDColoriOS7Test.h" +#import +#import + +@implementation EDColoriOS7Test + +- (void)testiOS7ColorsCount +{ + STAssertTrue([UIColor iOS7Colors].count == 11, @"Invalid number of colors: %@.", @([UIColor iOS7Colors].count)); +} + +- (void)testiOS7GradientPairs +{ + STAssertTrue([UIColor iOS7GradientPairs].count == 10, @"Invalid number of gradient pairs: %@.", @([UIColor iOS7GradientPairs].count)); +} + +- (void)testiOS7ColorsRed +{ + UIColor *redColor = (UIColor *)[[UIColor iOS7Colors] firstObject]; + STAssertTrue([redColor isEqual:[UIColor iOS7redColor]], @"First color is not red."); + STAssertTrue([redColor isEqual:[UIColor colorWithHex:0xFF3B30]], @"Green color is not 0x4CD964"); +} + +- (void)testiOS7ColorsGreenGradientPair +{ + NSArray *greenGradientPair = [UIColor iOS7greenGradient]; + STAssertTrue(greenGradientPair.count == 2, @"Invalid number of colors in a gradient pair."); + UIColor *fromColor = (id) [greenGradientPair firstObject]; + UIColor *toColor = (id) [greenGradientPair lastObject]; + STAssertTrue([fromColor isEqual:[UIColor iOS7greenGradientStartColor]], @"First color is incorrect."); + STAssertTrue([fromColor isEqual:[UIColor colorWithHex:0x87FC70]], @"First color is incorrect."); + STAssertTrue([toColor isEqual:[UIColor iOS7greenGradientEndColor]], @"Second color is incorrect."); + STAssertTrue([toColor isEqual:[UIColor colorWithHex:0x0BD318]], @"Second color is incorrect."); +} + +@end