源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2020-01-17 12:51 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:IOS程序开发之禁止输入表情符号实例代码
废话不多说了,先给大家展示效果图。 [b]一,效果图。 [/b] [img]http://files.jb51.net/file_images/article/201604/2016041310085218.jpg[/img] [b]二,工程图。 [/b] [img]http://files.jb51.net/file_images/article/201604/2016041310085219.jpg[/img] [b]三,代码。[/b] [b]RootViewController.h[/b]
#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;
}
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部