Skip to content

Commit

Permalink
Add style customizability to VENCalculatorInputView.
Browse files Browse the repository at this point in the history
  • Loading branch information
ayanonagon committed Feb 13, 2014
1 parent bccf195 commit a5a05bc
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 10 deletions.
17 changes: 17 additions & 0 deletions VENCalculatorInputView/VENCalculatorInputView.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,24 @@
@interface VENCalculatorInputView : UIView <UIInputViewAudioFeedback>

@property (weak, nonatomic) id<VENCalculatorInputViewDelegate> delegate;

@property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *numberButtonCollection;
@property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *operationButtonCollection;


/**-----------------------------------------------------------------------------
* @name Customizing colors
* -----------------------------------------------------------------------------
*/

@property (strong, nonatomic) UIColor *buttonTitleColor;
@property (strong, nonatomic) UIFont *buttonTitleFont;
@property (strong, nonatomic) UIColor *buttonHighlightedColor;

@property (strong, nonatomic) UIColor *numberButtonBackgroundColor;
@property (strong, nonatomic) UIColor *numberButtonBorderColor;

@property (strong, nonatomic) UIColor *operationButtonBackgroundColor;
@property (strong, nonatomic) UIColor *operationButtonBorderColor;

@end
82 changes: 72 additions & 10 deletions VENCalculatorInputView/VENCalculatorInputView.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,26 @@ @implementation VENCalculatorInputView
- (id)initWithFrame:(CGRect)frame {
self = [[[NSBundle mainBundle] loadNibNamed:@"VENCalculatorInputView" owner:self options:nil] firstObject];
if (self) {
// Set customizable properties
[self setNumberButtonBackgroundColor:[UIColor colorWithWhite:0.98828 alpha:1]];
[self setNumberButtonBorderColor:[UIColor colorWithRed:193/255.0f green:195/255.0f blue:199/255.0f alpha:1]];
[self setOperationButtonBackgroundColor:[UIColor colorWithRed:193/255.0f green:196/255.0f blue:200/255.0f alpha:1]];
[self setOperationButtonBorderColor:[UIColor colorWithRed:172/255.0f green:174/255.0f blue:177/255.0f alpha:1]];
[self setButtonHighlightedColor:[UIColor grayColor]];
[self setButtonTitleColor:[UIColor darkTextColor]];

// Set default properties
for (UIButton *numberButton in self.numberButtonCollection) {
[self setupButton:numberButton];
[numberButton setBackgroundColor:[UIColor colorWithWhite:0.98828 alpha:1]];
numberButton.layer.borderColor = [UIColor colorWithRed:193/255.0f green:195/255.0f blue:199/255.0f alpha:1].CGColor;
}
for (UIButton *operationButton in self.operationButtonCollection) {
[self setupButton:operationButton];
[operationButton setBackgroundColor:[UIColor colorWithRed:193/255.0f green:196/255.0f blue:200/255.0f alpha:1]];
operationButton.layer.borderColor = [UIColor colorWithRed:172/255.0f green:174/255.0f blue:177/255.0f alpha:1].CGColor;
}
}
return self;
}

- (void)setupButton:(UIButton *)button {
button.adjustsImageWhenHighlighted = YES;
[button setBackgroundImage:nil forState:UIControlStateNormal];
[button setBackgroundImage:nil forState:UIControlStateHighlighted];
[button setTitleShadowColor:[UIColor blackColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColor darkTextColor] forState:UIControlStateNormal];
[button setBackgroundImage:[self imageWithColor:[UIColor grayColor] size:CGSizeMake(50, 50)] forState:UIControlStateHighlighted];
button.layer.borderWidth = 0.25f;
}

Expand Down Expand Up @@ -65,4 +64,67 @@ - (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size {
return image;
}


#pragma mark - Properties

- (void)setButtonTitleColor:(UIColor *)buttonTitleColor {
_buttonTitleColor = buttonTitleColor;
for (UIButton *numberButton in self.numberButtonCollection) {
[numberButton setTitleColor:buttonTitleColor forState:UIControlStateNormal];
}
for (UIButton *operationButton in self.operationButtonCollection) {
[operationButton setTitleColor:buttonTitleColor forState:UIControlStateNormal];
}
}

- (void)setButtonTitleFont:(UIFont *)buttonTitleFont {
_buttonTitleFont = buttonTitleFont;
for (UIButton *numberButton in self.numberButtonCollection) {
numberButton.titleLabel.font = buttonTitleFont;
}
for (UIButton *operationButton in self.operationButtonCollection) {
operationButton.titleLabel.font = buttonTitleFont;
}
}

- (void)setButtonHighlightedColor:(UIColor *)buttonHighlightedColor {
_buttonHighlightedColor = buttonHighlightedColor;
for (UIButton *numberButton in self.numberButtonCollection) {
[numberButton setBackgroundImage:[self imageWithColor:buttonHighlightedColor size:CGSizeMake(50, 50)]
forState:UIControlStateHighlighted];
}
for (UIButton *operationButton in self.operationButtonCollection) {
[operationButton setBackgroundImage:[self imageWithColor:buttonHighlightedColor size:CGSizeMake(50, 50)]
forState:UIControlStateHighlighted];
}
}

- (void)setNumberButtonBackgroundColor:(UIColor *)numberButtonBackgroundColor {
_numberButtonBackgroundColor = numberButtonBackgroundColor;
for (UIButton *numberButton in self.numberButtonCollection) {
numberButton.backgroundColor = numberButtonBackgroundColor;
}
}

- (void)setNumberButtonBorderColor:(UIColor *)numberButtonBorderColor {
_numberButtonBorderColor = numberButtonBorderColor;
for (UIButton *numberButton in self.numberButtonCollection) {
numberButton.layer.borderColor = numberButtonBorderColor.CGColor;
}
}

- (void)setOperationButtonBackgroundColor:(UIColor *)operationButtonBackgroundColor {
_operationButtonBackgroundColor = operationButtonBackgroundColor;
for (UIButton *operationButton in self.operationButtonCollection) {
operationButton.backgroundColor = operationButtonBackgroundColor;
}
}

- (void)setOperationButtonBorderColor:(UIColor *)operationButtonBorderColor {
_operationButtonBorderColor = operationButtonBorderColor;
for (UIButton *operationButton in self.operationButtonCollection) {
operationButton.layer.borderColor = operationButtonBorderColor.CGColor;
}
}

@end

0 comments on commit a5a05bc

Please sign in to comment.