Skip to content

Commit

Permalink
Color picker cell should have a color well.
Browse files Browse the repository at this point in the history
  • Loading branch information
fcanas committed Oct 23, 2012
1 parent c599e7e commit cf6d9d4
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 11 deletions.
30 changes: 30 additions & 0 deletions FCSettingsBooster.xcodeproj/project.pbxproj
Expand Up @@ -21,6 +21,7 @@
E7B46A8116350E600057592F /* FCColorPickerCellSpec.mm in Sources */ = {isa = PBXBuildFile; fileRef = E7B46A8016350E600057592F /* FCColorPickerCellSpec.mm */; };
E7B46A8416350F410057592F /* NSUserDefaults+UIColor.m in Sources */ = {isa = PBXBuildFile; fileRef = E7B46A8316350F410057592F /* NSUserDefaults+UIColor.m */; };
E7B46A8516350F410057592F /* NSUserDefaults+UIColor.m in Sources */ = {isa = PBXBuildFile; fileRef = E7B46A8316350F410057592F /* NSUserDefaults+UIColor.m */; };
E7B46A87163627070057592F /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E7B46A86163627070057592F /* libPods.a */; };
E7B58C6E1634D98C00967966 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E7B58C6D1634D98C00967966 /* UIKit.framework */; };
E7B58C701634D98C00967966 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E7B58C6F1634D98C00967966 /* Foundation.framework */; };
E7B58C721634D98C00967966 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E7B58C711634D98C00967966 /* CoreGraphics.framework */; };
Expand Down Expand Up @@ -50,6 +51,8 @@
E7B46A8016350E600057592F /* FCColorPickerCellSpec.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = FCColorPickerCellSpec.mm; path = Specs/FCColorPickerCellSpec.mm; sourceTree = "<group>"; };
E7B46A8216350F410057592F /* NSUserDefaults+UIColor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSUserDefaults+UIColor.h"; sourceTree = "<group>"; };
E7B46A8316350F410057592F /* NSUserDefaults+UIColor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSUserDefaults+UIColor.m"; sourceTree = "<group>"; };
E7B46A86163627070057592F /* libPods.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libPods.a; path = "../Pods/build/Release-iphoneos/libPods.a"; sourceTree = "<group>"; };
E7B46A8916365AF40057592F /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
E7B58C691634D98C00967966 /* FCSettingsBooster.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FCSettingsBooster.app; sourceTree = BUILT_PRODUCTS_DIR; };
E7B58C6D1634D98C00967966 /* UIKit.framework */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
E7B58C6F1634D98C00967966 /* Foundation.framework */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
Expand Down Expand Up @@ -78,6 +81,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
E7B46A87163627070057592F /* libPods.a in Frameworks */,
E7B46A571634F2F80057592F /* UIKit.framework in Frameworks */,
E7B46A581634F2F80057592F /* Foundation.framework in Frameworks */,
E7B46A591634F2F80057592F /* CoreGraphics.framework in Frameworks */,
Expand Down Expand Up @@ -113,6 +117,7 @@
E7B46A5B1634F2F80057592F /* Supporting Files */ = {
isa = PBXGroup;
children = (
E7B46A86163627070057592F /* libPods.a */,
E7B46A5C1634F2F80057592F /* Specs-Info.plist */,
E7B46A5D1634F2F80057592F /* InfoPlist.strings */,
E7B46A601634F2F80057592F /* main.m */,
Expand All @@ -124,6 +129,7 @@
E7B58C5E1634D98C00967966 = {
isa = PBXGroup;
children = (
E7B46A8916365AF40057592F /* QuartzCore.framework */,
E7B58CB01634DA2000967966 /* FCSettingsBooster */,
E7B58C731634D98C00967966 /* FCSettingsBoosterAppResources */,
E7B46A5A1634F2F80057592F /* Specs */,
Expand Down Expand Up @@ -205,6 +211,7 @@
E7B46A511634F2F80057592F /* Sources */,
E7B46A521634F2F80057592F /* Frameworks */,
E7B46A531634F2F80057592F /* Resources */,
E7B46A88163627AD0057592F /* ShellScript */,
);
buildRules = (
);
Expand Down Expand Up @@ -300,6 +307,19 @@
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Pods-resources.sh\"\n";
};
E7B46A88163627AD0057592F /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Pods-resources.sh\"\n";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand Down Expand Up @@ -378,12 +398,17 @@
);
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Specs/Specs-Prefix.pch";
HEADER_SEARCH_PATHS = "${PODS_HEADERS_SEARCH_PATHS}";
INFOPLIST_FILE = "Specs/Specs-Info.plist";
OTHER_LDFLAGS = (
"-ObjC",
"-all_load",
"-lstdc++",
);
PODS_BUILD_HEADERS_SEARCH_PATHS = "\"${PODS_ROOT}/BuildHeaders\" \"${PODS_ROOT}/BuildHeaders/UIColor-Utilities\" \"${PODS_ROOT}/BuildHeaders/iOS-Color-Picker\"";
PODS_HEADERS_SEARCH_PATHS = "${PODS_PUBLIC_HEADERS_SEARCH_PATHS}";
PODS_PUBLIC_HEADERS_SEARCH_PATHS = "\"${PODS_ROOT}/Headers\" \"${PODS_ROOT}/Headers/UIColor-Utilities\" \"${PODS_ROOT}/Headers/iOS-Color-Picker\"";
PODS_ROOT = "${SRCROOT}/Pods";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
Expand All @@ -400,13 +425,18 @@
);
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Specs/Specs-Prefix.pch";
HEADER_SEARCH_PATHS = "${PODS_HEADERS_SEARCH_PATHS}";
INFOPLIST_FILE = "Specs/Specs-Info.plist";
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
OTHER_LDFLAGS = (
"-ObjC",
"-all_load",
"-lstdc++",
);
PODS_BUILD_HEADERS_SEARCH_PATHS = "\"${PODS_ROOT}/BuildHeaders\" \"${PODS_ROOT}/BuildHeaders/UIColor-Utilities\" \"${PODS_ROOT}/BuildHeaders/iOS-Color-Picker\"";
PODS_HEADERS_SEARCH_PATHS = "${PODS_PUBLIC_HEADERS_SEARCH_PATHS}";
PODS_PUBLIC_HEADERS_SEARCH_PATHS = "\"${PODS_ROOT}/Headers\" \"${PODS_ROOT}/Headers/UIColor-Utilities\" \"${PODS_ROOT}/Headers/iOS-Color-Picker\"";
PODS_ROOT = "${SRCROOT}/Pods";
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
};
Expand Down
5 changes: 5 additions & 0 deletions FCSettingsBooster/FCColorPickerCell.m
Expand Up @@ -8,6 +8,9 @@

#import "FCColorPickerCell.h"

#import <iOS-Color-Picker/FCColorSwatchView.h>
#import "NSUserDefaults+UIColor.h"

@implementation FCColorPickerCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
Expand All @@ -23,6 +26,8 @@ - (id)initWithReuseIdentifier:(NSString *)reuseIdentifier labelText:(NSString *)
self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
if (self) {
self.textLabel.text = label;
self.accessoryView = [[FCColorSwatchView alloc] initWithFrame:CGRectMake(0, 0, 79, 27)];
((FCColorSwatchView *)self.accessoryView).color = [[NSUserDefaults standardUserDefaults] colorForKey:key];
}
return self;
}
Expand Down
10 changes: 8 additions & 2 deletions FCSettingsBoosterAppResources/FCViewController.m
Expand Up @@ -9,6 +9,7 @@
#import "FCViewController.h"

#import "FCSwitchCell.h"
#import "FCColorPickerCell.h"

@interface FCViewController ()

Expand All @@ -30,11 +31,16 @@ - (void)didReceiveMemoryWarning


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
return [[FCSwitchCell alloc] initWithReuseIdentifier:@"b" labelText:@"My Preference" andKey:@"preferenceKey"];
if (indexPath.row == 1) {
return [[FCSwitchCell alloc] initWithReuseIdentifier:@"b" labelText:@"My Preference" andKey:@"preferenceKey"];
} else {
return [[FCColorPickerCell alloc] initWithReuseIdentifier:@"b" labelText:@"My Preference" andKey:@"colorPreferenceKey"];
}

}

@end
39 changes: 30 additions & 9 deletions Specs/Specs/FCColorPickerCellSpec.mm
@@ -1,22 +1,23 @@
#import "FCColorPickerCell.h"
#import "NSUserDefaults+UIColor.h"
#import <iOS-Color-Picker/FCColorSwatchView.h>

using namespace Cedar::Matchers;
using namespace Cedar::Doubles;

SPEC_BEGIN(FCColorPickerCellSpec)

describe(@"FCColorPickerCell", ^{
__block FCColorPickerCell *model;
static NSString *preferenceKey = @"colorKey";
__block FCColorPickerCell *model;
static NSString *preferenceKey = @"colorKey";

beforeEach(^{
[[NSUserDefaults standardUserDefaults] setColor:[UIColor blueColor] forKey:preferenceKey];
[[NSUserDefaults standardUserDefaults] synchronize];
model = [[FCColorPickerCell alloc] initWithReuseIdentifier:@"r"
labelText:@"Color Preference"
andKey:preferenceKey];
});
beforeEach(^{
[[NSUserDefaults standardUserDefaults] setColor:[UIColor blueColor] forKey:preferenceKey];
[[NSUserDefaults standardUserDefaults] synchronize];
model = [[FCColorPickerCell alloc] initWithReuseIdentifier:@"r"
labelText:@"Color Preference"
andKey:preferenceKey];
});

describe(@"init", ^(){
it(@"should show the correct name in its label", ^(){
Expand All @@ -26,6 +27,26 @@

});

describe(@"colorSwatch", ^(){
it(@"should have a FCColorSwatchView for an accessory view", ^(){
model.accessoryView should be_instance_of([FCColorSwatchView class]);
});

it(@"should set up a color swatch view of the correct size", ^(){
model.accessoryView.frame.size.width should equal(79.0f);
model.accessoryView.frame.size.height should equal(27.0f);
});

it(@"should have the color that corresponds to the user preference", ^(){
CGFloat r,g,b,a;
[((FCColorSwatchView *)model.accessoryView).color getRed:&r green:&g blue:&b alpha:&a];
r should equal(0.0f);
g should equal(0.0f);
b should equal(1.0f);
a should equal(1.0f);
});
});

});

SPEC_END

0 comments on commit cf6d9d4

Please sign in to comment.