diff --git a/Example/ISEmojiViewSample/ViewController.m b/Example/ISEmojiViewSample/ViewController.m index 5ba8ffe..452e0e6 100644 --- a/Example/ISEmojiViewSample/ViewController.m +++ b/Example/ISEmojiViewSample/ViewController.m @@ -9,7 +9,9 @@ #import "ViewController.h" #import "ISEmojiView.h" -@interface ViewController () +@interface ViewController () + +@property (nonatomic, strong) UITextView *textView; @end @@ -19,18 +21,23 @@ [super viewDidLoad]; // init TextView - UITextView *textView = [[UITextView alloc] initWithFrame:self.view.frame]; - [self.view addSubview:textView]; + self.textView = [[UITextView alloc] initWithFrame:self.view.frame]; + [self.view addSubview:self.textView]; // init ISEmojiView ISEmojiView *emojiView = [[ISEmojiView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 216)]; - textView.inputView = emojiView; + emojiView.delegate = self; + self.textView.inputView = emojiView; - [textView becomeFirstResponder]; + [self.textView becomeFirstResponder]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } +-(void)emojiView:(ISEmojiView *)emojiView didSelectEmoji:(NSString *)emoji{ + self.textView.text = [self.textView.text stringByAppendingString:emoji]; +} + @end diff --git a/ISEmojiView/ISEmojiView.h b/ISEmojiView/ISEmojiView.h index 8bce411..ea3243a 100644 --- a/ISEmojiView/ISEmojiView.h +++ b/ISEmojiView/ISEmojiView.h @@ -8,6 +8,16 @@ #import +@protocol ISEmojiViewDelegate; + @interface ISEmojiView : UIView +@property (nonatomic, assign) id delegate; + @end + +@protocol ISEmojiViewDelegate + +-(void)emojiView:(ISEmojiView *)emojiView didSelectEmoji:(NSString *)emoji; + +@end \ No newline at end of file diff --git a/ISEmojiView/ISEmojiView.m b/ISEmojiView/ISEmojiView.m index e976901..6bc66ec 100644 --- a/ISEmojiView/ISEmojiView.m +++ b/ISEmojiView/ISEmojiView.m @@ -55,10 +55,12 @@ static const CGFloat EmojiFontSize = 32; NSString *emoji = self.emojis[i]; + // init Emoji Button UIButton *emojiButton = [UIButton buttonWithType:UIButtonTypeCustom]; emojiButton.titleLabel.font = [UIFont fontWithName:@"Apple color emoji" size:EmojiFontSize]; [emojiButton setTitle:emoji forState:UIControlStateNormal]; - + [emojiButton addTarget:self action:@selector(emojiButtonPressed:) forControlEvents:UIControlEventTouchUpInside]; + // Pagination if (i % (rowNum * colNum) == 0) { page ++; // Increase the number of pages @@ -111,4 +113,10 @@ static const CGFloat EmojiFontSize = 32; self.pageControl.currentPage = newPageNumber; } +- (void)emojiButtonPressed:(UIButton *)button { + if ([self.delegate respondsToSelector:@selector(emojiView:didSelectEmoji:)]) { + [self.delegate emojiView:self didSelectEmoji:button.titleLabel.text]; + } +} + @end