Skip to content
This repository has been archived by the owner on Jul 14, 2020. It is now read-only.

Commit

Permalink
Show a space key when there's only one KeyItemGroup on the keyboard, c…
Browse files Browse the repository at this point in the history
…lose #1
  • Loading branch information
YuAo committed Apr 22, 2014
1 parent 90e2a35 commit 21d4d73
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 10 deletions.
6 changes: 5 additions & 1 deletion WUEmoticonsKeyboard/WUEmoticonsKeyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ extern CGSize const WUEmoticonsKeyboardDefaultSize;

typedef NS_ENUM(NSUInteger, WUEmoticonsKeyboardButton) {
WUEmoticonsKeyboardButtonKeyboardSwitch,
WUEmoticonsKeyboardButtonBackspace
WUEmoticonsKeyboardButtonBackspace,
WUEmoticonsKeyboardButtonSpace
};

@interface WUEmoticonsKeyboard : UIView <UIAppearance,UIAppearanceContainer>
Expand Down Expand Up @@ -54,6 +55,9 @@ typedef NS_ENUM(NSUInteger, WUEmoticonsKeyboardButton) {
- (void)setBackgroundImage:(UIImage *)image forButton:(WUEmoticonsKeyboardButton)button state:(UIControlState)state UI_APPEARANCE_SELECTOR;
- (UIImage *)backgroundImageForButton:(WUEmoticonsKeyboardButton)button state:(UIControlState)state;

- (void)setAttributedTitle:(NSAttributedString *)title forButton:(WUEmoticonsKeyboardButton)button state:(UIControlState)state UI_APPEARANCE_SELECTOR;
- (NSAttributedString *)attributedTitleForButton:(WUEmoticonsKeyboardButton)button state:(UIControlState)state;

@property (nonatomic) CGFloat toolsViewHeight UI_APPEARANCE_SELECTOR; //Default 45.0f

@end
Expand Down
18 changes: 15 additions & 3 deletions WUEmoticonsKeyboard/WUEmoticonsKeyboard.m
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ - (void)setup {
[weakSelf backspace];
}];

[toolsView setSpaceButtonTappedBlock:^{
[weakSelf inputText:@" "];
}];

[toolsView setKeyItemGroupSelectedBlock:^(WUEmoticonsKeyboardKeyItemGroup *keyItemGroup) {
[weakSelf switchToKeyItemGroup:keyItemGroup];
}];
Expand Down Expand Up @@ -259,13 +263,12 @@ - (UIButton *)emoticonsKeyboardButtonOfType:(WUEmoticonsKeyboardButton)type {
switch (type) {
case WUEmoticonsKeyboardButtonKeyboardSwitch:
return self.toolsView.keyboardSwitchButton;
break;
case WUEmoticonsKeyboardButtonBackspace:
return self.toolsView.backspaceButton;
break;
case WUEmoticonsKeyboardButtonSpace:
return self.toolsView.spaceButton;
default:
return nil;
break;
}
}

Expand All @@ -287,6 +290,15 @@ - (UIImage *)backgroundImageForButton:(WUEmoticonsKeyboardButton)button state:(U
return [[self emoticonsKeyboardButtonOfType:button] backgroundImageForState:state];
}

- (void)setAttributedTitle:(NSAttributedString *)title forButton:(WUEmoticonsKeyboardButton)button state:(UIControlState)state {
[[self emoticonsKeyboardButtonOfType:button] setAttributedTitle:title forState:state];
[self setNeedsLayout];
}

- (NSAttributedString *)attributedTitleForButton:(WUEmoticonsKeyboardButton)button state:(UIControlState)state {
return [[self emoticonsKeyboardButtonOfType:button] attributedTitleForState:state];
}

- (void)setBackgroundImage:(UIImage *)image {
[self.backgroundImageView setImage:image];
}
Expand Down
2 changes: 2 additions & 0 deletions WUEmoticonsKeyboard/WUEmoticonsKeyboardToolsView.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@

@property (nonatomic,copy) void (^keyboardSwitchButtonTappedBlock)(void);
@property (nonatomic,copy) void (^backspaceButtonTappedBlock)(void);
@property (nonatomic,copy) void (^spaceButtonTappedBlock)(void);
@property (nonatomic,copy) void (^keyItemGroupSelectedBlock)(WUEmoticonsKeyboardKeyItemGroup *keyItemGroup);

@property (nonatomic,weak,readonly) UIButton *keyboardSwitchButton;
@property (nonatomic,weak,readonly) UIButton *backspaceButton;
@property (nonatomic,weak,readonly) UIButton *spaceButton;

@end
23 changes: 22 additions & 1 deletion WUEmoticonsKeyboard/WUEmoticonsKeyboardToolsView.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
@interface WUEmoticonsKeyboardToolsView ()
@property (nonatomic,weak,readwrite) UIButton *keyboardSwitchButton;
@property (nonatomic,weak,readwrite) UIButton *backspaceButton;
@property (nonatomic,weak,readwrite) UIButton *spaceButton;
@property (nonatomic,weak) UISegmentedControl *segmentedControl;
@end

Expand All @@ -37,6 +38,12 @@ - (id)initWithFrame:(CGRect)frame
[segmentedControl addTarget:self action:@selector(segmentedControlValueChanged:) forControlEvents:UIControlEventValueChanged];
[self addSubview:segmentedControl];
self.segmentedControl = segmentedControl;

UIButton *spaceButton = [UIButton buttonWithType:UIButtonTypeCustom];
spaceButton.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[spaceButton addTarget:self action:@selector(spaceButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:spaceButton];
self.spaceButton = spaceButton;
}
return self;
}
Expand All @@ -49,7 +56,7 @@ - (void)layoutSubviews {

self.keyboardSwitchButton.frame = (CGRect){CGPointZero,keyboardSwitchButtonSize};
self.backspaceButton.frame = (CGRect){ {CGRectGetWidth(self.bounds) - backspaceButtonSize.width, 0} ,backspaceButtonSize};
self.segmentedControl.frame = CGRectMake(keyboardSwitchButtonSize.width, 0, CGRectGetWidth(self.bounds) - keyboardSwitchButtonSize.width - backspaceButtonSize.width, CGRectGetHeight(self.bounds));
self.spaceButton.frame = self.segmentedControl.frame = CGRectMake(keyboardSwitchButtonSize.width, 0, CGRectGetWidth(self.bounds) - keyboardSwitchButtonSize.width - backspaceButtonSize.width, CGRectGetHeight(self.bounds));
}

- (void)setKeyItemGroups:(NSArray *)keyItemGroups {
Expand All @@ -66,6 +73,14 @@ - (void)setKeyItemGroups:(NSArray *)keyItemGroups {
self.segmentedControl.selectedSegmentIndex = 0;
[self segmentedControlValueChanged:self.segmentedControl];
}

if (keyItemGroups.count > 1) {
self.segmentedControl.hidden = NO;
self.spaceButton.hidden = YES;
} else {
self.segmentedControl.hidden = YES;
self.spaceButton.hidden = NO;
}
}

- (void)segmentedControlValueChanged:(UISegmentedControl *)sender {
Expand Down Expand Up @@ -98,4 +113,10 @@ - (void)backspaceButtonTapped:(UIButton *)sender {
}
}

- (void)spaceButtonTapped:(UIButton *)sender {
if (self.spaceButtonTappedBlock) {
self.spaceButtonTappedBlock();
}
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,21 @@ + (WUEmoticonsKeyboard *)sharedEmoticonsKeyboard {
//Keyboard appearance

//Custom text icons scroll background
UIView *textGridBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [textIconsLayout collectionViewContentSize].width, [textIconsLayout collectionViewContentSize].height)];
textGridBackgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
textGridBackgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"keyboard_grid_bg"]];
[textIconsLayout.collectionView addSubview:textGridBackgroundView];
if (textIconsLayout.collectionView) {
UIView *textGridBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [textIconsLayout collectionViewContentSize].width, [textIconsLayout collectionViewContentSize].height)];
textGridBackgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
textGridBackgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"keyboard_grid_bg"]];
[textIconsLayout.collectionView addSubview:textGridBackgroundView];
}

//Custom utility keys
[keyboard setImage:[UIImage imageNamed:@"keyboard_switch"] forButton:WUEmoticonsKeyboardButtonKeyboardSwitch state:UIControlStateNormal];
[keyboard setImage:[UIImage imageNamed:@"keyboard_del"] forButton:WUEmoticonsKeyboardButtonBackspace state:UIControlStateNormal];
[keyboard setImage:[UIImage imageNamed:@"keyboard_switch_pressed"] forButton:WUEmoticonsKeyboardButtonKeyboardSwitch state:UIControlStateHighlighted];
[keyboard setImage:[UIImage imageNamed:@"keyboard_del_pressed"] forButton:WUEmoticonsKeyboardButtonBackspace state:UIControlStateHighlighted];

[keyboard setAttributedTitle:[[NSAttributedString alloc] initWithString:NSLocalizedString(@"Space", @"") attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:15], NSForegroundColorAttributeName: [UIColor darkGrayColor]}] forButton:WUEmoticonsKeyboardButtonSpace state:UIControlStateNormal];
[keyboard setBackgroundImage:[[UIImage imageNamed:@"keyboard_segment_normal"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 10, 0, 10)] forButton:WUEmoticonsKeyboardButtonSpace state:UIControlStateNormal];

//Keyboard background
[keyboard setBackgroundImage:[[UIImage imageNamed:@"keyboard_bg"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 1, 0, 1)]];

Expand Down

0 comments on commit 21d4d73

Please sign in to comment.