From b867e0cf128b224678e396da3ed00fd8cd817e4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Luis=20Campa=C3=B1a?= Date: Tue, 21 Aug 2012 13:48:12 +0200 Subject: [PATCH 1/3] Added new color customizations for text and off tint Added on/off text (and shadow) color support Added tint off color change --- DCRoundSwitch/DCRoundSwitch.h | 8 +++ DCRoundSwitch/DCRoundSwitch.m | 76 ++++++++++++++++++++++++ DCRoundSwitch/DCRoundSwitchToggleLayer.h | 8 +++ DCRoundSwitch/DCRoundSwitchToggleLayer.m | 72 +++++++++++++++++++--- readme.md | 6 +- 5 files changed, 162 insertions(+), 8 deletions(-) diff --git a/DCRoundSwitch/DCRoundSwitch.h b/DCRoundSwitch/DCRoundSwitch.h index dd693de..d555471 100644 --- a/DCRoundSwitch/DCRoundSwitch.h +++ b/DCRoundSwitch/DCRoundSwitch.h @@ -8,6 +8,7 @@ // http://domesticcat.com.au/projects // http://github.com/domesticcatsoftware/DCRoundSwitch // +// Modified by Jose Luis Campaña to add text and offTint color support #import #import @@ -23,6 +24,13 @@ @property (nonatomic, copy) NSString *onText; // default: 'ON' - automatically localized @property (nonatomic, copy) NSString *offText; // default: 'OFF' - automatically localized +//iZ3 Additions +@property (nonatomic, retain) UIColor *onTextColor; +@property (nonatomic, retain) UIColor *offTextColor; +@property (nonatomic, retain) UIColor *onTextShadowColor; +@property (nonatomic, retain) UIColor *offTextShadowColor; +@property (nonatomic, retain) UIColor *offTintColor; + + (Class)knobLayerClass; + (Class)outlineLayerClass; + (Class)toggleLayerClass; diff --git a/DCRoundSwitch/DCRoundSwitch.m b/DCRoundSwitch/DCRoundSwitch.m index 8e0549b..702f4e8 100644 --- a/DCRoundSwitch/DCRoundSwitch.m +++ b/DCRoundSwitch/DCRoundSwitch.m @@ -8,6 +8,7 @@ // http://domesticcat.com.au/projects // http://github.com/domesticcatsoftware/DCRoundSwitch // +// Modified by Jose Luis Campaña to add text and offTint color support #import "DCRoundSwitch.h" #import "DCRoundSwitchToggleLayer.h" @@ -34,6 +35,13 @@ @implementation DCRoundSwitch @synthesize on, onText, offText; @synthesize onTintColor; +//iZ3 Additions +@synthesize onTextColor = _onTextColor; +@synthesize offTextColor = _offTextColor; +@synthesize onTextShadowColor = _onTextShadowColor; +@synthesize offTextShadowColor = _offTextShadowColor; +@synthesize offTintColor = _offTintColor; + #pragma mark - #pragma mark Init & Memory Managment @@ -47,6 +55,13 @@ - (void)dealloc [onTintColor release]; [onText release]; [offText release]; + + //iZ3 Additions + [_onTextColor release]; + [_offTextColor release]; + [_offTextShadowColor release]; + [_onTextShadowColor release]; + [_offTintColor release]; [super dealloc]; } @@ -465,4 +480,65 @@ - (void)setOffText:(NSString *)newOffText } } +#pragma mark iZ3 Additions +- (void)setOnTextColor:(UIColor *)onTextColor +{ + if (_onTextColor != onTextColor) + { + [_onTextColor release]; + _onTextColor = [onTextColor retain]; + + self.toggleLayer.onTextColor = onTextColor; + [self.toggleLayer setNeedsDisplay]; + } +} + +- (void)setOffTextColor:(UIColor *)offTextColor +{ + if (_offTextColor != offTextColor) + { + [_offTextColor release]; + _offTextColor = [offTextColor retain]; + + self.toggleLayer.offTextColor = offTextColor; + [self.toggleLayer setNeedsDisplay]; + } +} + +- (void)setOnTextShadowColor:(UIColor *)onTextShadowColor +{ + if (_onTextShadowColor != onTextShadowColor) + { + [_onTextShadowColor release]; + _onTextShadowColor = [onTextShadowColor retain]; + + self.toggleLayer.onTextShadowColor = onTextShadowColor; + [self.toggleLayer setNeedsDisplay]; + } +} + +- (void)setOffTextShadowColor:(UIColor *)offTextShadowColor +{ + if (_offTextShadowColor != offTextShadowColor) + { + [_offTextShadowColor release]; + _offTextShadowColor = [offTextShadowColor retain]; + + self.toggleLayer.offTextShadowColor = offTextShadowColor; + [self.toggleLayer setNeedsDisplay]; + } +} + +-(void)setOffTintColor:(UIColor *)offTintColor +{ + if (_offTintColor != offTintColor) + { + [_offTintColor release]; + _offTintColor = [offTintColor retain]; + + self.toggleLayer.offTintColor = _offTintColor; + [self.toggleLayer setNeedsDisplay]; + } +} + @end diff --git a/DCRoundSwitch/DCRoundSwitchToggleLayer.h b/DCRoundSwitch/DCRoundSwitchToggleLayer.h index e56c631..11e5869 100644 --- a/DCRoundSwitch/DCRoundSwitchToggleLayer.h +++ b/DCRoundSwitch/DCRoundSwitchToggleLayer.h @@ -8,6 +8,7 @@ // http://domesticcat.com.au/projects // http://github.com/domesticcatsoftware/DCRoundSwitch // +// Modified by Jose Luis Campaña to add text and offTint color support #import #import @@ -21,6 +22,13 @@ @property (nonatomic) BOOL drawOnTint; @property (nonatomic) BOOL clip; +//iZ3 Additions +@property (nonatomic, retain) UIColor *onTextColor; +@property (nonatomic, retain) UIColor *offTextColor; +@property (nonatomic, retain) UIColor *onTextShadowColor; +@property (nonatomic, retain) UIColor *offTextShadowColor; +@property (nonatomic, retain) UIColor *offTintColor; + - (id)initWithOnString:(NSString *)anOnString offString:(NSString *)anOffString onTintColor:(UIColor *)anOnTintColor; @end diff --git a/DCRoundSwitch/DCRoundSwitchToggleLayer.m b/DCRoundSwitch/DCRoundSwitchToggleLayer.m index 99e0550..c1cf5b8 100644 --- a/DCRoundSwitch/DCRoundSwitchToggleLayer.m +++ b/DCRoundSwitch/DCRoundSwitchToggleLayer.m @@ -8,6 +8,7 @@ // http://domesticcat.com.au/projects // http://github.com/domesticcatsoftware/DCRoundSwitch // +// Modified by Jose Luis Campaña to add text and offTint color support #import "DCRoundSwitchToggleLayer.h" @@ -17,15 +18,68 @@ @implementation DCRoundSwitchToggleLayer @synthesize clip; @synthesize labelFont; +//iZ3 Additions +@synthesize onTextColor = _onTextColor; +@synthesize offTextColor = _offTextColor; +@synthesize onTextShadowColor = _onTextShadowColor; +@synthesize offTextShadowColor = _offTextShadowColor; +@synthesize offTintColor = _offTintColor; + +-(void)iniController +{ + //iZ3 Additions + _onTextColor = [[UIColor colorWithWhite:0.45 alpha:1.0] retain]; + _offTextColor = [[UIColor whiteColor] retain]; + _onTextShadowColor = [[UIColor whiteColor] retain]; + _offTextShadowColor = [[UIColor colorWithWhite:0.52 alpha:1.0] retain]; + _offTintColor = [[UIColor colorWithWhite:0.963 alpha:1.0] retain]; +} + + - (void)dealloc { [onString release]; [offString release]; [onTintColor release]; + + //iZ3 + [_offTextShadowColor release]; + [_offTextColor release]; + [_onTextColor release]; + [_onTextShadowColor release]; + [_offTintColor release]; + [super dealloc]; } +-(id)initWithCoder:(NSCoder *)aDecoder +{ + if (self = [super initWithCoder:aDecoder]) + { + [self iniController]; + } + return self; +} + +-(id)init +{ + if ((self = [super init])) + { + [self iniController]; + } + return self; +} + +-(id) initWithLayer:(id)layer +{ + if(self = [super initWithLayer:layer]) + { + [self iniController]; + } + return self; +} + - (id)initWithOnString:(NSString *)anOnString offString:(NSString *)anOffString onTintColor:(UIColor *)anOnTintColor { if ((self = [super init])) @@ -33,6 +87,9 @@ - (id)initWithOnString:(NSString *)anOnString offString:(NSString *)anOffString self.onString = anOnString; self.offString = anOffString; self.onTintColor = anOnTintColor; + + [self iniController]; + } return self; @@ -64,7 +121,8 @@ - (void)drawInContext:(CGContextRef)context } // off tint color (white) - CGContextSetFillColorWithColor(context, [UIColor colorWithWhite:0.963 alpha:1.0].CGColor); +// CGContextSetFillColorWithColor(context, [UIColor colorWithWhite:0.963 alpha:1.0].CGColor); + CGContextSetFillColorWithColor(context, _offTintColor.CGColor); CGContextFillRect(context, CGRectMake(knobCenter, 0, self.bounds.size.width - knobCenter, self.bounds.size.height)); // knob shadow @@ -83,17 +141,17 @@ - (void)drawInContext:(CGContextRef)context // 'ON' state label (self.onString) CGSize onTextSize = [self.onString sizeWithFont:self.labelFont]; CGPoint onTextPoint = CGPointMake((textSpaceWidth - onTextSize.width) / 2.0 + knobRadius * .15, floorf((self.bounds.size.height - onTextSize.height) / 2.0) + 1.0); - [[UIColor colorWithWhite:0.45 alpha:1.0] set]; // .2 & .4 - [self.onString drawAtPoint:CGPointMake(onTextPoint.x, onTextPoint.y - 1.0) withFont:self.labelFont]; - [[UIColor whiteColor] set]; + [_onTextShadowColor set]; + [self.onString drawAtPoint:CGPointMake(onTextPoint.x, onTextPoint.y - 1.0) withFont:self.labelFont]; + [_onTextColor set]; [self.onString drawAtPoint:onTextPoint withFont:self.labelFont]; // 'OFF' state label (self.offString) CGSize offTextSize = [self.offString sizeWithFont:self.labelFont]; CGPoint offTextPoint = CGPointMake(textSpaceWidth + (textSpaceWidth - offTextSize.width) / 2.0 + knobRadius * .86, floorf((self.bounds.size.height - offTextSize.height) / 2.0) + 1.0); - [[UIColor whiteColor] set]; - [self.offString drawAtPoint:CGPointMake(offTextPoint.x, offTextPoint.y + 1.0) withFont:self.labelFont]; - [[UIColor colorWithWhite:0.52 alpha:1.0] set]; + [_offTextShadowColor set]; + [self.offString drawAtPoint:CGPointMake(offTextPoint.x, offTextPoint.y + 1.0) withFont:self.labelFont]; + [_offTextColor set]; [self.offString drawAtPoint:offTextPoint withFont:self.labelFont]; UIGraphicsPopContext(); diff --git a/readme.md b/readme.md index 17be213..37fcdc2 100644 --- a/readme.md +++ b/readme.md @@ -36,4 +36,8 @@ Made available under the MIT License. Attribution would be nice. Collaboration ------------- -If you have any feature requests/bugfixes etc. feel free to help out and send a pull request, or create a new issue. \ No newline at end of file +If you have any feature requests/bugfixes etc. feel free to help out and send a pull request, or create a new issue. + +iZ3 Additions +============= +Added more customizations properties as chante on/off text color and shadow + offTint \ No newline at end of file From 61d6523a12a4170b480adf12f2c1b0f8b2832869 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Luis=20Campa=C3=B1a?= Date: Tue, 21 Aug 2012 13:54:16 +0200 Subject: [PATCH 2/3] Added a little more info at read me file --- readme.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 37fcdc2..f48a4bc 100644 --- a/readme.md +++ b/readme.md @@ -40,4 +40,12 @@ If you have any feature requests/bugfixes etc. feel free to help out and send a iZ3 Additions ============= -Added more customizations properties as chante on/off text color and shadow + offTint \ No newline at end of file + + +Added more customizations properties as chante on/off text color and shadow + offTint +------------------------------------------------------------------------------------- +* onTextColor +* offTextColor +* onTextShadowColor +* offTextShadowColor +* offTintColor \ No newline at end of file From 98b4ada843968d3bce496cc92ffdbb6249539de7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=20Luis=20Campa=C3=B1a?= Date: Tue, 21 Aug 2012 13:55:23 +0200 Subject: [PATCH 3/3] Readme --- readme.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/readme.md b/readme.md index f48a4bc..978e4a1 100644 --- a/readme.md +++ b/readme.md @@ -41,9 +41,8 @@ If you have any feature requests/bugfixes etc. feel free to help out and send a iZ3 Additions ============= +More color customizations: -Added more customizations properties as chante on/off text color and shadow + offTint -------------------------------------------------------------------------------------- * onTextColor * offTextColor * onTextShadowColor