Skip to content

Commit

Permalink
Merge pull request #17 from dblock/ios7
Browse files Browse the repository at this point in the history
Ported Ios7 colors.
  • Loading branch information
thisandagain committed Apr 23, 2014
2 parents ab24f2e + 20b0c77 commit 19c2b39
Show file tree
Hide file tree
Showing 15 changed files with 506 additions and 289 deletions.
32 changes: 18 additions & 14 deletions Demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -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 = "<group>"; };
3C205ADC19083CC600B3C2B4 /* EDColoriOS7ViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EDColoriOS7ViewController.m; sourceTree = "<group>"; };
3C205ADF19083E5F00B3C2B4 /* EDColoriOS7ViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = EDColoriOS7ViewController.xib; sourceTree = "<group>"; };
3C205AE31908448B00B3C2B4 /* EDColoriOS7ViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = EDColoriOS7ViewCell.xib; sourceTree = "<group>"; };
3C562C6518DC8B4500DE3F38 /* Images */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Images; sourceTree = "<group>"; };
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; };
Expand All @@ -53,11 +59,7 @@
3CE9EC0C18FC602D0034ADA7 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
3CE9EC2218FC64850034ADA7 /* EDFirstViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = EDFirstViewController.xib; sourceTree = "<group>"; };
3CE9EC2418FC648D0034ADA7 /* EDSecondViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = EDSecondViewController.xib; sourceTree = "<group>"; };
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 = "<group>"; };
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 = "<group>"; };
/* End PBXFileReference section */

Expand All @@ -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;
};
Expand All @@ -83,7 +84,6 @@
3CB0E6DC18C8B9E2009CE8DB /* Demo */,
3CB0E6D518C8B9E2009CE8DB /* Frameworks */,
3CB0E6D418C8B9E2009CE8DB /* Products */,
BD0E280B71AE47E499695C40 /* Pods.xcconfig */,
FE4DCA04C7CC4E32A9AEA10B /* Pods-Demo.xcconfig */,
);
sourceTree = "<group>";
Expand All @@ -103,17 +103,15 @@
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 = "<group>";
};
3CB0E6DC18C8B9E2009CE8DB /* Demo */ = {
isa = PBXGroup;
children = (
3C205AE31908448B00B3C2B4 /* EDColoriOS7ViewCell.xib */,
3CE9EC2418FC648D0034ADA7 /* EDSecondViewController.xib */,
3CE9EC2218FC64850034ADA7 /* EDFirstViewController.xib */,
3CE9EC0C18FC602D0034ADA7 /* main.m */,
Expand All @@ -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 = "<group>";
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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 */,
Expand Down
4 changes: 3 additions & 1 deletion Demo/EDAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import "EDSecondViewController.h"
#import "EDThirdViewController.h"
#import "EDFourthViewController.h"
#import "EDColoriOS7ViewController.h"

@implementation EDAppDelegate

Expand All @@ -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;
Expand Down
33 changes: 33 additions & 0 deletions Demo/EDColoriOS7ViewCell.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="5056" systemVersion="13C64" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="3733"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" id="jf5-0k-RYm">
<rect key="frame" x="0.0" y="0.0" width="160" height="160"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
<rect key="frame" x="0.0" y="0.0" width="160" height="160"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView userInteractionEnabled="NO" tag="200" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="3xd-CC-TuP">
<rect key="frame" x="-16" y="-19" width="193" height="195"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
</imageView>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" tag="100" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="wlC-EW-yu0">
<rect key="frame" x="0.0" y="41" width="160" height="71"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</view>
<size key="customSize" width="100" height="100"/>
</collectionViewCell>
</objects>
</document>
13 changes: 13 additions & 0 deletions Demo/EDColoriOS7ViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// EDColoriOS7iOS7ViewController.h
// Demo
//
// Created by Daniel Doubrovkine on 4/23/14.
// Copyright (c) 2014 Andrew Sliwinski. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface EDColoriOS7ViewController : UIViewController
@property (nonatomic, strong) IBOutlet UICollectionView *collectionView;
@end
137 changes: 137 additions & 0 deletions Demo/EDColoriOS7ViewController.m
Original file line number Diff line number Diff line change
@@ -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 <EDColor/UIColor+iOS7.h>
#import <Foundation/Foundation.h>

@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
Loading

0 comments on commit 19c2b39

Please sign in to comment.