Skip to content

Commit

Permalink
THContactBubble: added THBubbleColor instead tree colors
Browse files Browse the repository at this point in the history
added initWithName:color:borderColor method

It is more comfortable to have one color property instead of three.
  • Loading branch information
dvor committed Dec 6, 2012
1 parent 2b70176 commit d3d0c40
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 19 deletions.
6 changes: 6 additions & 0 deletions ContactPicker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
29A71C151644834B005286F1 /* THContactPickerView.m in Sources */ = {isa = PBXBuildFile; fileRef = 29A71C141644834B005286F1 /* THContactPickerView.m */; };
29A71C1816448473005286F1 /* THContactBubble.m in Sources */ = {isa = PBXBuildFile; fileRef = 29A71C1716448473005286F1 /* THContactBubble.m */; };
6AE31FCC1644DB2C00505230 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6AE31FCB1644DB2C00505230 /* QuartzCore.framework */; };
84F796481670C79500A8965D /* THBubbleColor.m in Sources */ = {isa = PBXBuildFile; fileRef = 84F796471670C79500A8965D /* THBubbleColor.m */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -45,6 +46,8 @@
29A71C1616448473005286F1 /* THContactBubble.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = THContactBubble.h; sourceTree = "<group>"; };
29A71C1716448473005286F1 /* THContactBubble.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = THContactBubble.m; sourceTree = "<group>"; };
6AE31FCB1644DB2C00505230 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
84F796461670C79500A8965D /* THBubbleColor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = THBubbleColor.h; sourceTree = "<group>"; };
84F796471670C79500A8965D /* THBubbleColor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = THBubbleColor.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -103,6 +106,8 @@
29A71C0E164482BB005286F1 /* THContactPickerViewController.h */,
29A71C0F164482BB005286F1 /* THContactPickerViewController.m */,
29A71C10164482BB005286F1 /* THContactPickerViewController.xib */,
84F796461670C79500A8965D /* THBubbleColor.h */,
84F796471670C79500A8965D /* THBubbleColor.m */,
);
path = ContactPicker;
sourceTree = "<group>";
Expand Down Expand Up @@ -192,6 +197,7 @@
29A71C11164482BB005286F1 /* THContactPickerViewController.m in Sources */,
29A71C151644834B005286F1 /* THContactPickerView.m in Sources */,
29A71C1816448473005286F1 /* THContactBubble.m in Sources */,
84F796481670C79500A8965D /* THBubbleColor.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
21 changes: 21 additions & 0 deletions ContactPicker/THBubbleColor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// THBubbleColor.h
// ContactPicker
//
// Created by Dmitry Vorobjov on 12/6/12.
// Copyright (c) 2012 Tristan Himmelman. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface THBubbleColor : NSObject

@property (nonatomic, strong) UIColor *gradientTop;
@property (nonatomic, strong) UIColor *gradientBottom;
@property (nonatomic, strong) UIColor *border;

- (id)initWithGradientTop:(UIColor *)gradientTop
gradientBottom:(UIColor *)gradientBottom
border:(UIColor *)border;

@end
24 changes: 24 additions & 0 deletions ContactPicker/THBubbleColor.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// THBubbleColor.m
// ContactPicker
//
// Created by Dmitry Vorobjov on 12/6/12.
// Copyright (c) 2012 Tristan Himmelman. All rights reserved.
//

#import "THBubbleColor.h"

@implementation THBubbleColor

- (id)initWithGradientTop:(UIColor *)gradientTop
gradientBottom:(UIColor *)gradientBottom
border:(UIColor *)border {
if (self = [super init]) {
self.gradientTop = gradientTop;
self.gradientBottom = gradientBottom;
self.border = border;
}
return self;
}

@end
14 changes: 7 additions & 7 deletions ContactPicker/THContactBubble.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import "THBubbleColor.h"

@class THContactBubble;

Expand All @@ -27,15 +28,14 @@
@property (nonatomic, assign) id <THContactBubbleDelegate>delegate;
@property (nonatomic, strong) CAGradientLayer *gradientLayer;

@property (nonatomic, strong) UIColor *colorGradientTop;
@property (nonatomic, strong) UIColor *colorGradientBottom;
@property (nonatomic, strong) UIColor *colorBorder;

@property (nonatomic, strong) UIColor *colorSelectedGradientTop;
@property (nonatomic, strong) UIColor *colorSelectedGradientBottom;
@property (nonatomic, strong) UIColor *colorSelectedBorder;
@property (nonatomic, strong) THBubbleColor *color;
@property (nonatomic, strong) THBubbleColor *selectedColor;

- (id)initWithName:(NSString *)name;
- (id)initWithName:(NSString *)name
color:(THBubbleColor *)color
selectedColor:(THBubbleColor *)selectedColor;

- (void)select;
- (void)unSelect;
- (void)setFont:(UIFont *)font;
Expand Down
38 changes: 26 additions & 12 deletions ContactPicker/THContactBubble.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,33 @@ @implementation THContactBubble
#define kColorSelectedBorder [UIColor colorWithRed:56.0/255.0 green:0/255.0 blue:233.0/255.0 alpha:1.0]

- (id)initWithName:(NSString *)name {
if ([self initWithName:name color:nil selectedColor:nil]) {

}
return self;
}

- (id)initWithName:(NSString *)name
color:(THBubbleColor *)color
selectedColor:(THBubbleColor *)selectedColor {
self = [super init];
if (self){
self.name = name;
self.isSelected = NO;

if (! color)
color = [[THBubbleColor alloc] initWithGradientTop:kColorGradientTop
gradientBottom:kColorGradientBottom
border:kColorBorder];

if (! selectedColor)
color = [[THBubbleColor alloc] initWithGradientTop:kColorSelectedGradientTop
gradientBottom:kColorSelectedGradientBottom
border:kColorSelectedBorder];

// set colors to defaults
self.colorGradientTop = kColorGradientTop;
self.colorGradientBottom = kColorGradientBottom;
self.colorBorder = kColorBorder;

self.colorSelectedGradientTop = kColorSelectedGradientTop;
self.colorSelectedGradientBottom = kColorSelectedGradientBottom;
self.colorSelectedBorder = kColorSelectedBorder;
self.color = color;
self.selectedColor = selectedColor;


[self setupView];
}
Expand Down Expand Up @@ -101,9 +115,9 @@ - (void)select {
}

CALayer *viewLayer = [self layer];
viewLayer.borderColor = self.colorSelectedBorder.CGColor;
viewLayer.borderColor = self.selectedColor.border.CGColor;

self.gradientLayer.colors = [NSArray arrayWithObjects:(id)[self.colorSelectedGradientTop CGColor], (id)[self.colorSelectedGradientBottom CGColor], nil];
self.gradientLayer.colors = [NSArray arrayWithObjects:(id)[self.selectedColor.gradientTop CGColor], (id)[self.selectedColor.gradientBottom CGColor], nil];

self.label.textColor = [UIColor whiteColor];

Expand All @@ -114,9 +128,9 @@ - (void)select {

- (void)unSelect {
CALayer *viewLayer = [self layer];
viewLayer.borderColor = self.colorBorder.CGColor;
viewLayer.borderColor = self.color.border.CGColor;

self.gradientLayer.colors = [NSArray arrayWithObjects:(id)[self.colorGradientTop CGColor], (id)[self.colorGradientBottom CGColor], nil];
self.gradientLayer.colors = [NSArray arrayWithObjects:(id)[self.color.gradientTop CGColor], (id)[self.color.gradientBottom CGColor], nil];

self.label.textColor = [UIColor blackColor];

Expand Down

0 comments on commit d3d0c40

Please sign in to comment.