Add delegate callback
This commit is contained in:
parent
a55555dfcd
commit
366275e5aa
|
|
@ -9,7 +9,9 @@
|
|||
#import "ViewController.h"
|
||||
#import "ISEmojiView.h"
|
||||
|
||||
@interface ViewController ()
|
||||
@interface ViewController ()<ISEmojiViewDelegate>
|
||||
|
||||
@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
|
||||
|
|
|
|||
|
|
@ -8,6 +8,16 @@
|
|||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@protocol ISEmojiViewDelegate;
|
||||
|
||||
@interface ISEmojiView : UIView
|
||||
|
||||
@property (nonatomic, assign) id<ISEmojiViewDelegate> delegate;
|
||||
|
||||
@end
|
||||
|
||||
@protocol ISEmojiViewDelegate <NSObject>
|
||||
|
||||
-(void)emojiView:(ISEmojiView *)emojiView didSelectEmoji:(NSString *)emoji;
|
||||
|
||||
@end
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue