如何禁止输入表情符号呢?下面脚本之家小编给大家分享IOS程序开发之禁止输入表情符号实例代码,感兴趣的朋友参考下吧
废话不多说了,先给大家展示效果图。
一,效果图。

二,工程图。

三,代码。
RootViewController.h
#import <UIKit/UIKit.h>
@interface RootViewController : UIViewController
<UITextViewDelegate>
@end
RootViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
//初始化背景
[self addView];
}
#pragma -mark -functions
-(void)addView
{
UITextView *textView=[[UITextView alloc]initWithFrame:CGRectMake(50, 100, 200, 50)];
textView.backgroundColor=[UIColor redColor];
textView.delegate=self;
[self.view addSubview:textView];
}
#pragma -mark -UITextViewDelegate
- (void)textViewDidChange:(UITextView *)textView
{
NSRange textRange = [textView selectedRange];
[textView setText:[self disable_emoji:[textView text]]];
[textView setSelectedRange:textRange];
}
//禁止输入表情
- (NSString *)disable_emoji:(NSString *)text
{
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[^\\u0020-\\u007E\\u00A0-\\u00BE\\u2E80-\\uA4CF\\uF900-\\uFAFF\\uFE30-\\uFE4F\\uFF00-\\uFFEF\\u0080-\\u009F\\u2000-\\u201f\r\n]" options:NSRegularExpressionCaseInsensitive error:nil];
NSString *modifiedString = [regex stringByReplacingMatchesInString:text
options:0
range:NSMakeRange(0, [text length])
withTemplate:@""];
return modifiedString;
}
织梦狗教程
本文标题为:IOS程序开发之禁止输入表情符号实例代码
基础教程推荐
猜你喜欢
- IOS 播放系统提示音使用总结(AudioToolbox) 2023-03-01
- 解决Android Studio突然不显示logcat日志的问题 2023-02-04
- Android开发使用RecyclerView添加点击事件实例详解 2023-06-15
- Android多返回栈技术 2023-04-15
- Flutter绘图组件之CustomPaint使用详解 2023-05-12
- Android中的webview监听每次URL变化实例 2023-01-23
- IOS应用内跳转系统设置相关界面的方法 2022-11-20
- android studio按钮监听的5种方法实例详解 2023-01-12
- iOS开发教程之XLForm的基本使用方法 2023-05-01
- Flutter手势密码的实现示例(附demo) 2023-04-11
