首页 > 系统 > iOS > 正文

IOS程序开发之禁止输入表情符号实例代码

2019-10-21 18:54:50
字体:
来源:转载
供稿:网友
如何禁止输入表情符号呢?下面VEVB武林网小编给大家分享IOS程序开发之禁止输入表情符号实例代码,感兴趣的朋友参考下吧
 

废话不多说了,先给大家展示效果图。

一,效果图。

IOS程序开发,表情符号

二,工程图。

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:textoptions:0range:NSMakeRange(0, [text length])withTemplate:@""];return modifiedString;}
 


注:相关教程知识阅读请移步到IOS开发频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表