diff --git a/WUEmoticonsKeyboard/WUEmoticonsKeyboard.h b/WUEmoticonsKeyboard/WUEmoticonsKeyboard.h index 9521a82..9216775 100644 --- a/WUEmoticonsKeyboard/WUEmoticonsKeyboard.h +++ b/WUEmoticonsKeyboard/WUEmoticonsKeyboard.h @@ -18,7 +18,8 @@ extern CGSize const WUEmoticonsKeyboardDefaultSize; typedef NS_ENUM(NSUInteger, WUEmoticonsKeyboardButton) { WUEmoticonsKeyboardButtonKeyboardSwitch, - WUEmoticonsKeyboardButtonBackspace + WUEmoticonsKeyboardButtonBackspace, + WUEmoticonsKeyboardButtonSpace }; @interface WUEmoticonsKeyboard : UIView @@ -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 diff --git a/WUEmoticonsKeyboard/WUEmoticonsKeyboard.m b/WUEmoticonsKeyboard/WUEmoticonsKeyboard.m index cc477fd..e985484 100644 --- a/WUEmoticonsKeyboard/WUEmoticonsKeyboard.m +++ b/WUEmoticonsKeyboard/WUEmoticonsKeyboard.m @@ -162,6 +162,10 @@ - (void)setup { [weakSelf backspace]; }]; + [toolsView setSpaceButtonTappedBlock:^{ + [weakSelf inputText:@" "]; + }]; + [toolsView setKeyItemGroupSelectedBlock:^(WUEmoticonsKeyboardKeyItemGroup *keyItemGroup) { [weakSelf switchToKeyItemGroup:keyItemGroup]; }]; @@ -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; } } @@ -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]; } diff --git a/WUEmoticonsKeyboard/WUEmoticonsKeyboardToolsView.h b/WUEmoticonsKeyboard/WUEmoticonsKeyboardToolsView.h index 2933389..66b1e3b 100644 --- a/WUEmoticonsKeyboard/WUEmoticonsKeyboardToolsView.h +++ b/WUEmoticonsKeyboard/WUEmoticonsKeyboardToolsView.h @@ -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 diff --git a/WUEmoticonsKeyboard/WUEmoticonsKeyboardToolsView.m b/WUEmoticonsKeyboard/WUEmoticonsKeyboardToolsView.m index 840933a..91b86d2 100644 --- a/WUEmoticonsKeyboard/WUEmoticonsKeyboardToolsView.m +++ b/WUEmoticonsKeyboard/WUEmoticonsKeyboardToolsView.m @@ -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 @@ -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; } @@ -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 { @@ -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 { @@ -98,4 +113,10 @@ - (void)backspaceButtonTapped:(UIButton *)sender { } } +- (void)spaceButtonTapped:(UIButton *)sender { + if (self.spaceButtonTappedBlock) { + self.spaceButtonTappedBlock(); + } +} + @end diff --git a/WUEmoticonsKeyboardDemo/WUEmoticonsKeyboardDemo/WUDemoKeyboardBuilder.m b/WUEmoticonsKeyboardDemo/WUEmoticonsKeyboardDemo/WUDemoKeyboardBuilder.m index 539cf79..4535486 100644 --- a/WUEmoticonsKeyboardDemo/WUEmoticonsKeyboardDemo/WUDemoKeyboardBuilder.m +++ b/WUEmoticonsKeyboardDemo/WUEmoticonsKeyboardDemo/WUDemoKeyboardBuilder.m @@ -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)]];