苹果ios自定义表情输入_ios8自定义键盘开发
程序员文章站
2022-02-12 21:22:43
...
本Demo是一个IOS的自定义 emoji表情键盘、运行效果非常好、自定义功能强大、主要实现了两大功能一是自定义 emoji表情键盘、二是可以信息输入框、也就是说可以输入表情和文字、界面也非常漂亮、下面是程序运行效果
核心代码
#import "DemoViewController.h" #import "STInputBar.h" @interface DemoViewController () @end @implementation DemoViewController{ STInputBar *_inputBar; UIScrollView *_scrollView; UILabel *_textWindow; NSArray *_names; } - (void)viewDidLoad { [super viewDidLoad]; _inputBar = [STInputBar inputBar]; _inputBar.center = CGPointMake(CGRectGetWidth(self.view.frame)/2, CGRectGetHeight(self.view.bounds)-CGRectGetHeight(_inputBar.frame) CGRectGetHeight(_inputBar.frame)/2); [_inputBar setFitWhenKeyboardShowOrHide:YES]; _inputBar.placeHolder = @"小明的故事..."; _scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds]; _scrollView.backgroundColor = [UIColor groupTableViewBackgroundColor]; _scrollView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag; _scrollView.alwaysBounceVertical = YES; _scrollView.contentInset = UIEdgeInsetsMake(-10, 0, CGRectGetHeight(_inputBar.frame), 0); [self.view addSubview:_scrollView]; _textWindow = [[UILabel alloc] initWithFrame:_scrollView.bounds]; _textWindow.numberOfLines = 0; _textWindow.tag = 0; [_scrollView addSubview:_textWindow]; [self.view addSubview:_inputBar]; __weak typeof(self) weakSelf = self; [_inputBar setDidSendClicked:^(NSString *text) { [weakSelf updateMessage:text]; }]; _names = @[@"小明",@"老师"]; } - (void)updateMessage:(NSString *)message{ static NSDictionary *_txtAtt = nil; if (!_txtAtt){ _txtAtt = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:16], NSForegroundColorAttributeName:[UIColor darkTextColor]}; } static NSDictionary *_timeAtt = nil; if (!_timeAtt){ _timeAtt = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:13], NSForegroundColorAttributeName:[UIColor colorWithWhite:0.2 alpha:0.5]}; } NSString *name = _names[_textWindow.tag]; _inputBar.placeHolder = @"对话..."; NSString *reply = [NSString stringWithFormat:@"回复 %@",_names[0]]; if (1 == _textWindow.tag){ name = [NSString stringWithFormat:@"%@ %@",name,reply]; } else{ _inputBar.placeHolder = reply; } NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithAttributedString:_textWindow.attributedText]; [text appendAttributedString:[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@" --- %@ --- %@ ", [self time],name] attributes:_timeAtt]]; [text appendAttributedString:[[NSAttributedString alloc] initWithString:message attributes:_txtAtt]]; [_textWindow setAttributedText:text]; CGSize size = [_textWindow sizeThatFits: CGSizeMake(CGRectGetWidth(self.view.frame), 100000)]; _textWindow.frame = CGRectMake(0, 0, size.width, size.height); _scrollView.contentSize = CGSizeMake(CGRectGetWidth(self.view.frame), CGRectGetHeight(_textWindow.frame)); _textWindow.tag = (_textWindow.tag 1)%_names.count; } - (NSString *)time{ static NSDateFormatter *_dateFormatter = nil; if (!_dateFormatter){ _dateFormatter = [NSDateFormatter new]; _dateFormatter.dateFormat = @"HH:mm:ss"; } return [_dateFormatter stringFromDate:[NSDate date]]; } @end
若资源对你有帮助、扫描下方的二维码、关注DD博客微信公众号(ddblogs)吧
最后给贴上Demo的源代码、希望对大家有用、有兴趣的哥们可以下载看看
源代码下载链接: http://dwtedx.com/download.html?bdkey=s/1pJ9TJxp 密码: ukh8