Skip to content

Commit 48eed8d

Browse files
committedDec 17, 2012
Improve API
UIImage+ColorArt category for ease of use.
1 parent 7981c41 commit 48eed8d

File tree

6 files changed

+51
-11
lines changed

6 files changed

+51
-11
lines changed
 

‎ColorArt.xcodeproj/project.pbxproj

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
B62026F416788B34004F3873 /* PCFadedImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = B62026E516788B34004F3873 /* PCFadedImageView.m */; };
2626
B63779DC16799D4200E79BFE /* SLColorArt.m in Sources */ = {isa = PBXBuildFile; fileRef = B63779DA16799D4200E79BFE /* SLColorArt.m */; };
2727
B63779DF16799D7E00E79BFE /* LBGradient.m in Sources */ = {isa = PBXBuildFile; fileRef = B63779DE16799D7E00E79BFE /* LBGradient.m */; };
28+
B6934671167F215400B7590D /* UIImage+ColorArt.m in Sources */ = {isa = PBXBuildFile; fileRef = B6934670167F215400B7590D /* UIImage+ColorArt.m */; };
2829
B6CDCAA5167D6F5700A8D642 /* UIImage+Scale.m in Sources */ = {isa = PBXBuildFile; fileRef = B6CDCAA4167D6F5700A8D642 /* UIImage+Scale.m */; };
2930
/* End PBXBuildFile section */
3031

@@ -55,6 +56,8 @@
5556
B63779DA16799D4200E79BFE /* SLColorArt.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SLColorArt.m; sourceTree = "<group>"; };
5657
B63779DD16799D7E00E79BFE /* LBGradient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LBGradient.h; sourceTree = "<group>"; };
5758
B63779DE16799D7E00E79BFE /* LBGradient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LBGradient.m; sourceTree = "<group>"; };
59+
B693466F167F215400B7590D /* UIImage+ColorArt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+ColorArt.h"; sourceTree = "<group>"; };
60+
B6934670167F215400B7590D /* UIImage+ColorArt.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+ColorArt.m"; sourceTree = "<group>"; };
5861
B6CDCAA3167D6F5700A8D642 /* UIImage+Scale.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+Scale.h"; sourceTree = "<group>"; };
5962
B6CDCAA4167D6F5700A8D642 /* UIImage+Scale.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+Scale.m"; sourceTree = "<group>"; };
6063
/* End PBXFileReference section */
@@ -144,6 +147,8 @@
144147
B63779DA16799D4200E79BFE /* SLColorArt.m */,
145148
B6CDCAA3167D6F5700A8D642 /* UIImage+Scale.h */,
146149
B6CDCAA4167D6F5700A8D642 /* UIImage+Scale.m */,
150+
B693466F167F215400B7590D /* UIImage+ColorArt.h */,
151+
B6934670167F215400B7590D /* UIImage+ColorArt.m */,
147152
);
148153
path = Classes;
149154
sourceTree = "<group>";
@@ -225,6 +230,7 @@
225230
B63779DC16799D4200E79BFE /* SLColorArt.m in Sources */,
226231
B63779DF16799D7E00E79BFE /* LBGradient.m in Sources */,
227232
B6CDCAA5167D6F5700A8D642 /* UIImage+Scale.m in Sources */,
233+
B6934671167F215400B7590D /* UIImage+ColorArt.m in Sources */,
228234
);
229235
runOnlyForDeploymentPostprocessing = 0;
230236
};

‎ColorArt/CAViewController.m

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#import "CAViewController.h"
1010
#import "SLColorArt.h"
1111
#import "UIImage+Scale.h"
12+
#import "UIImage+ColorArt.h"
1213
@interface CAViewController ()
1314

1415
@end
@@ -27,11 +28,9 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
2728
- (void)colorizeForImage:(UIImage *)image
2829
{
2930
image = [image scaledToSize:self.fadedImageView.frame.size];
30-
SLColorArt *colorArt = [[SLColorArt alloc] initWithImage:image scaledSize: self.fadedImageView.frame.size];
31-
CGRect f = self.fadedImageView.frame;
32-
f.size = colorArt.scaledImage.size;
31+
SLColorArt *colorArt = [image colorArt];
3332
self.fadedImageView.backgroundColor = colorArt.backgroundColor;
34-
self.fadedImageView.image = colorArt.scaledImage;
33+
self.fadedImageView.image = image;
3534
self.view.backgroundColor = colorArt.backgroundColor;
3635
self.headline.textColor = colorArt.primaryColor;
3736
self.subHeadline.textColor = colorArt.secondaryColor;

‎ColorArt/Classes/SLColorArt.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
@property(strong, nonatomic, readonly) UIColor *primaryColor;
2323
@property(strong, nonatomic, readonly) UIColor *secondaryColor;
2424
@property(strong, nonatomic, readonly) UIColor *detailColor;
25-
@property(nonatomic, copy) UIImage *scaledImage;
2625

27-
- (id)initWithImage:(UIImage*)image scaledSize:(CGSize)size;
26+
- (id)initWithImage:(UIImage*)image;
2827
@end

‎ColorArt/Classes/SLColorArt.m

+3-5
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ - (id)initWithColor:(UIColor*)color count:(NSUInteger)count;
4646

4747
@interface SLColorArt ()
4848
@property(nonatomic, copy) UIImage *image;
49-
@property CGSize scaledSize;
5049
@property(nonatomic,readwrite,strong) UIColor *backgroundColor;
5150
@property(nonatomic,readwrite,strong) UIColor *primaryColor;
5251
@property(nonatomic,readwrite,strong) UIColor *secondaryColor;
@@ -55,14 +54,13 @@ @interface SLColorArt ()
5554

5655
@implementation SLColorArt
5756

58-
- (id)initWithImage:(UIImage*)image scaledSize:(CGSize)size
57+
- (id)initWithImage:(UIImage*)image
5958
{
6059
self = [super init];
6160

6261
if (self)
6362
{
6463
self.image = image;
65-
self.scaledSize = size;
6664
[self _processImage];
6765
}
6866

@@ -71,7 +69,7 @@ - (id)initWithImage:(UIImage*)image scaledSize:(CGSize)size
7169

7270
- (void)_processImage
7371
{
74-
UIImage *finalImage = [self _scaleImage:self.image size:self.scaledSize];
72+
//UIImage *finalImage = [self _scaleImage:self.image size:self.scaledSize];
7573

7674
NSDictionary *colors = [self _analyzeImage:self.image];
7775

@@ -80,7 +78,7 @@ - (void)_processImage
8078
self.secondaryColor = [colors objectForKey:kAnalyzedSecondaryColor];
8179
self.detailColor = [colors objectForKey:kAnalyzedDetailColor];
8280

83-
self.scaledImage = finalImage;
81+
//self.scaledImage = finalImage;
8482
}
8583

8684
- (UIImage*)_scaleImage:(UIImage*)image size:(CGSize)scaledSize

‎ColorArt/Classes/UIImage+ColorArt.h

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// UIImage+ColorArt.h
3+
// ColorArt
4+
//
5+
// Created by Fred Leitz on 2012-12-17.
6+
// Copyright (c) 2012 Fred Leitz. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
#import "SLColorArt.h"
11+
12+
@interface UIImage (ColorArt)
13+
14+
- (SLColorArt*) colorArt;
15+
- (SLColorArt*) colorArt:(CGSize)scale;
16+
17+
@end

‎ColorArt/Classes/UIImage+ColorArt.m

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// UIImage+ColorArt.m
3+
// ColorArt
4+
//
5+
// Created by Fred Leitz on 2012-12-17.
6+
// Copyright (c) 2012 Fred Leitz. All rights reserved.
7+
//
8+
9+
#import "UIImage+ColorArt.h"
10+
#import "UIImage+Scale.h"
11+
@implementation UIImage (ColorArt)
12+
13+
- (SLColorArt *)colorArt:(CGSize)scale{
14+
return [[SLColorArt alloc] initWithImage:[self scaledToSize: scale]];
15+
}
16+
17+
- (SLColorArt *)colorArt{
18+
return [self colorArt:CGSizeMake(512, 512)];
19+
}
20+
21+
@end

0 commit comments

Comments
 (0)
Please sign in to comment.