你的位置:首页 > 软件开发 > 操作系统 > 【代码笔记】禁止输入表情符号

【代码笔记】禁止输入表情符号

发布时间:2016-04-13 10:00:09
一,效果图。二,工程图。三,代码。RootViewController.h#import <UIKit/UIKit.h>@interface RootViewController : UIViewController<UITextViewDelegate> ...

【代码笔记】禁止输入表情符号

一,效果图。

【代码笔记】禁止输入表情符号

二,工程图。

【代码笔记】禁止输入表情符号

三,代码。

RootViewController.h

#import <UIKit/UIKit.h>@interface RootViewController : UIViewController<UITextViewDelegate>@end
- (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;}
【代码笔记】禁止输入表情符号

 

 


 

 

海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com

原标题:【代码笔记】禁止输入表情符号

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录