IOS程序開發(fā)之禁止輸入表情符號實例代碼
更新時間:2016年04月13日 10:11:10 作者:Livia.Chen
如何禁止輸入表情符號呢?下面腳本之家小編給大家分享IOS程序開發(fā)之禁止輸入表情符號實例代碼,感興趣的朋友參考下吧
廢話不多說了,先給大家展示效果圖。
一,效果圖。
二,工程圖。
三,代碼。
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; }
相關(guān)文章
iOS Runntime 動態(tài)添加類方法并調(diào)用-class_addMethod
這篇文章主要介紹了iOS Runntime 動態(tài)添加類方法并調(diào)用-class_addMethod的相關(guān)資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2016-08-08ios利用RunLoop原理實現(xiàn)去監(jiān)控卡頓實例詳解
這篇文章主要為大家介紹了ios利用RunLoop原理實現(xiàn)去監(jiān)控卡頓實例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-09-09Xcode 下刪除Provisioning Profiles文件詳細(xì)介紹
這篇文章主要介紹了Xcode 下刪除Provisioning Profiles文件詳細(xì)介紹的相關(guān)資料,需要的朋友可以參考下2016-12-12