如何禁止输入表情符号呢?下面脚本之家小编给大家分享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程序开发之禁止输入表情符号实例代码


基础教程推荐
猜你喜欢
- Android开发Compose集成高德地图实例 2023-06-15
- Android实现短信验证码输入框 2023-04-29
- iOS开发使用XML解析网络数据 2022-11-12
- Android Compose自定义TextField实现自定义的输入框 2023-05-13
- IOS获取系统相册中照片的示例代码 2023-01-03
- Flutter进阶之实现动画效果(三) 2022-10-28
- iOS开发 全机型适配解决方法 2023-01-14
- iOS中如何判断当前网络环境是2G/3G/4G/5G/WiFi 2023-06-18
- iOS Crash常规跟踪方法及Bugly集成运用详细介绍 2023-01-18
- MVVMLight项目Model View结构及全局视图模型注入器 2023-05-07