Skip to content

Commit

Permalink
Merge pull request #8 from khaullen/master
Browse files Browse the repository at this point in the history
Modifies CYRKeyboardButton to allow initialization from interface builder
  • Loading branch information
illyabusigin committed Apr 20, 2015
2 parents 0ad5bf0 + da8a57b commit 9752ecc
Showing 1 changed file with 58 additions and 44 deletions.
102 changes: 58 additions & 44 deletions CYRKeyboardButton/CYRKeyboardButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,55 +64,69 @@ - (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
switch ([UIDevice currentDevice].userInterfaceIdiom) {
case UIUserInterfaceIdiomPhone:
_style = CYRKeyboardButtonStylePhone;
break;

case UIUserInterfaceIdiomPad:
_style = CYRKeyboardButtonStyleTablet;
break;

default:
break;
}

// Default appearance
_font = [UIFont systemFontOfSize:22.f];
_inputOptionsFont = [UIFont systemFontOfSize:24.f];
_keyColor = [UIColor whiteColor];
_keyTextColor = [UIColor blackColor];
_keyShadowColor = [UIColor colorWithRed:136 / 255.f green:138 / 255.f blue:142 / 255.f alpha:1];
_keyHighlightedColor = [UIColor colorWithRed:213/255.f green:214/255.f blue:216/255.f alpha:1];

// Styling
self.backgroundColor = [UIColor clearColor];
self.clipsToBounds = NO;
self.layer.masksToBounds = NO;
self.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;

// State handling
[self addTarget:self action:@selector(handleTouchDown) forControlEvents:UIControlEventTouchDown];
[self addTarget:self action:@selector(handleTouchUpInside) forControlEvents:UIControlEventTouchUpInside];

// Input label
UILabel *inputLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(frame), CGRectGetHeight(frame))];
inputLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
inputLabel.textAlignment = NSTextAlignmentCenter;
inputLabel.backgroundColor = [UIColor clearColor];
inputLabel.userInteractionEnabled = NO;
inputLabel.textColor = _keyTextColor;
inputLabel.font = _font;

[self addSubview:inputLabel];
_inputLabel = inputLabel;

[self updateDisplayStyle];
[self commonInit];
}

return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
[self commonInit];
}
return self;
}

- (void)commonInit
{
switch ([UIDevice currentDevice].userInterfaceIdiom) {
case UIUserInterfaceIdiomPhone:
_style = CYRKeyboardButtonStylePhone;
break;

case UIUserInterfaceIdiomPad:
_style = CYRKeyboardButtonStyleTablet;
break;

default:
break;
}

// Default appearance
_font = [UIFont systemFontOfSize:22.f];
_inputOptionsFont = [UIFont systemFontOfSize:24.f];
_keyColor = [UIColor whiteColor];
_keyTextColor = [UIColor blackColor];
_keyShadowColor = [UIColor colorWithRed:136 / 255.f green:138 / 255.f blue:142 / 255.f alpha:1];
_keyHighlightedColor = [UIColor colorWithRed:213/255.f green:214/255.f blue:216/255.f alpha:1];

// Styling
self.backgroundColor = [UIColor clearColor];
self.clipsToBounds = NO;
self.layer.masksToBounds = NO;
self.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;

// State handling
[self addTarget:self action:@selector(handleTouchDown) forControlEvents:UIControlEventTouchDown];
[self addTarget:self action:@selector(handleTouchUpInside) forControlEvents:UIControlEventTouchUpInside];

// Input label
UILabel *inputLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.frame), CGRectGetHeight(self.frame))];
inputLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
inputLabel.textAlignment = NSTextAlignmentCenter;
inputLabel.backgroundColor = [UIColor clearColor];
inputLabel.userInteractionEnabled = NO;
inputLabel.textColor = _keyTextColor;
inputLabel.font = _font;

[self addSubview:inputLabel];
_inputLabel = inputLabel;

[self updateDisplayStyle];
}

- (void)didMoveToSuperview
{
[self updateButtonPosition];
Expand Down

0 comments on commit 9752ecc

Please sign in to comment.