Permalink
Browse files

Updated setting and getting border colors and background colors

  • Loading branch information...
1 parent 83608c5 commit 8bebcb34b25c0682fbcbd85a11a851377871105d Soroush Khanlou committed Oct 25, 2012
Showing with 20 additions and 38 deletions.
  1. +1 −12 FTWButton/FTWButton.h
  2. +19 −26 FTWButton/FTWButton.m
View
@@ -1,5 +1,5 @@
//
-// FTWAnimatableGradientButton.h
+// FTWButton.h
// FTW
//
// Created by Soroush Khanlou on 1/26/12.
@@ -13,13 +13,6 @@
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
-typedef enum {
- FTWAnimatableGradientButtonStyleDelete = 0,
- FTWAnimatableGradientButtonStyleCancel,
- FTWAnimatableGradientButtonStyleDisabled,
- FTWAnimatableGradientButtonStyleBlue
-} FTWAnimatableGradientButtonStyle;
-
@interface FTWButton : UIControl
@property (nonatomic, assign) NSTextAlignment textAlignment;
@@ -33,8 +26,6 @@ typedef enum {
- (void) addYellowStyleForState:(UIControlState)state;
- (void) addBlackStyleForState:(UIControlState)state;
-
-
- (void) setFrame:(CGRect)frame forControlState:(UIControlState)controlState;
- (CGRect) frameForControlState:(UIControlState)controlState;
@@ -43,7 +34,6 @@ typedef enum {
//backrounds
- (void) setBackgroundColor:(UIColor*)color forControlState:(UIControlState)controlState;
-- (UIColor*) backgroundColorForControlState:(UIControlState)controlState;
- (void) setColors:(NSArray*)colors forControlState:(UIControlState)controlState;
- (NSArray*) colorsForControlState:(UIControlState)controlState;
@@ -53,7 +43,6 @@ typedef enum {
- (CGFloat) borderWidthForControlState:(UIControlState)controlState;
- (void) setBorderColor:(UIColor*)borderColor forControlState:(UIControlState)controlState;
-- (UIColor*) borderColorForControlState:(UIControlState)controlState;
- (void) setBorderColors:(NSArray*)borderColor forControlState:(UIControlState)controlState;
- (NSArray*) borderColorsForControlState:(UIControlState)controlState;
View
@@ -1,5 +1,5 @@
//
-// FTWAnimatableGradientButton.m
+// FTWButton.h
// FTW
//
// Created by Soroush Khanlou on 1/26/12.
@@ -27,13 +27,11 @@ @interface FTWButton()
@property (strong, nonatomic) NSMutableDictionary *textShadowOffsets;
@property (strong, nonatomic) NSMutableDictionary *borderWidths;
-@property (strong, nonatomic) NSMutableDictionary *borderColors;
@property (strong, nonatomic) NSMutableDictionary *borderGradients;
@property (strong, nonatomic) NSMutableDictionary *cornerRadii;
@property (strong, nonatomic) NSMutableDictionary *gradients;
-@property (strong, nonatomic) NSMutableDictionary *backgroundColors;
@property (strong, nonatomic) NSMutableDictionary *frames;
@property (strong, nonatomic) NSMutableDictionary *shadowColors;
@@ -48,8 +46,8 @@ @interface FTWButton()
@property (strong, nonatomic) NSMutableDictionary *icons;
-- (id) getValueFromDictionary:(NSDictionary*)dictionary forControlState:(UIControlState)controlState;
-- (void) setValue:(id)value inDictionary:(NSDictionary*)dictionary forControlState:(UIControlState)controlState;
+- (id) getValueFromDictionary:(NSMutableDictionary*)dictionary forControlState:(UIControlState)controlState;
+- (void) setValue:(id)value inDictionary:(NSMutableDictionary*)dictionary forControlState:(UIControlState)controlState;
- (void) configureViewForControlState:(UIControlState)controlState;
@@ -68,8 +66,8 @@ @implementation FTWButton
@synthesize label, selectedLabel;
@synthesize texts;
@synthesize textColors, textShadowColors, textShadowOffsets, textAlignment;
-@synthesize borderWidths, borderColors, borderGradients, cornerRadii;
-@synthesize gradients, backgroundColors, frames;
+@synthesize borderWidths, borderGradients, cornerRadii;
+@synthesize gradients, frames;
@synthesize shadowColors, shadowOffsets, shadowRadii, shadowOpacities;
@synthesize innerShadowColors, innerShadowOffsets, innerShadowRadii;
@synthesize icons;
@@ -145,9 +143,7 @@ - (void) commonInit {
- backgroundColors = [NSMutableDictionary new];
gradients = [NSMutableDictionary new];
- borderColors = [NSMutableDictionary new];
borderGradients = [NSMutableDictionary new];
borderWidths = [NSMutableDictionary new];
@@ -301,18 +297,18 @@ - (void) configureLayerPropertiesForControlState:(UIControlState)controlState {
//set background colors and gradients
backgroundLayer.colors = [self colorsForControlState:controlState];
- backgroundLayer.backgroundColor = [self backgroundColorForControlState:controlState].CGColor;
+ // backgroundLayer.backgroundColor = [self backgroundColorForControlState:controlState].CGColor;
//set border widths, colors, and gradients
if ([self borderWidthForControlState:controlState] > 0) {
if ([self borderColorsForControlState:controlState]) {
borderLayer.colors = [self borderColorsForControlState:controlState];
borderLayer.backgroundColor = [UIColor clearColor].CGColor;
} else {
- if ([self borderColorForControlState:controlState]) {
- borderLayer.backgroundColor = [self borderColorForControlState:controlState].CGColor;
+ if ([self borderColorsForControlState:controlState]) {
+ borderLayer.colors = [self borderColorsForControlState:controlState];
} else {
- borderLayer.backgroundColor = [self backgroundColorForControlState:controlState].CGColor;
+ borderLayer.colors = [self colorsForControlState:controlState];
}
}
}
@@ -403,12 +399,16 @@ - (UIControlState) currentControlState {
#pragma mark - default setter and getter
-- (void) setValue:(id)value inDictionary:(NSDictionary*)dictionary forControlState:(UIControlState)controlState {
- [dictionary setValue:value forKey:[NSString stringWithFormat:@"%d",controlState]];
+- (void) setValue:(id)value inDictionary:(NSMutableDictionary*)dictionary forControlState:(UIControlState)controlState {
+ if (value) {
+ [dictionary setValue:value forKey:[NSString stringWithFormat:@"%d",controlState]];
+ } else {
+ [dictionary removeObjectForKey:[NSString stringWithFormat:@"%d",controlState]];
+ }
[self configureViewForControlState:[self currentControlState]];
}
-- (id) getValueFromDictionary:(NSDictionary*)dictionary forControlState:(UIControlState)controlState {
+- (id) getValueFromDictionary:(NSMutableDictionary*)dictionary forControlState:(UIControlState)controlState {
if ([dictionary valueForKey:[NSString stringWithFormat:@"%d",controlState]]) {
return [dictionary valueForKey:[NSString stringWithFormat:@"%d",controlState]];
}
@@ -608,11 +608,7 @@ - (UIImage*) iconForControlState:(UIControlState)controlState {
#pragma mark background colors
- (void) setBackgroundColor:(UIColor*)color forControlState:(UIControlState)controlState {
- [self setValue:color inDictionary:backgroundColors forControlState:controlState];
-}
-
-- (UIColor*) backgroundColorForControlState:(UIControlState)controlState {
- return [self getValueFromDictionary:backgroundColors forControlState:controlState];
+ [self setValue:@[ [color copy], [color copy] ] inDictionary:gradients forControlState:controlState];
}
- (void) setColors:(NSArray*)colors forControlState:(UIControlState)controlState {
@@ -660,11 +656,7 @@ - (NSArray*) borderColorsForControlState:(UIControlState)controlState {
- (void) setBorderColor:(UIColor*)borderColor forControlState:(UIControlState)controlState {
- [self setValue:borderColor inDictionary:borderColors forControlState:controlState];
-}
-
-- (UIColor*) borderColorForControlState:(UIControlState)controlState {
- return [self getValueFromDictionary:borderColors forControlState:controlState];
+ [self setValue:@[[borderColor copy], [borderColor copy]] inDictionary:borderGradients forControlState:controlState];
}
#pragma mark - built in styles
@@ -851,4 +843,5 @@ - (void) addBlueStyleForState:(UIControlState)state {
}
+
@end

0 comments on commit 8bebcb3

Please sign in to comment.