我是靠谱客的博主 秀丽胡萝卜,最近开发中收集的这篇文章主要介绍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-\u201frn]" options:NSRegularExpressionCaseInsensitive error:nil];
NSString *modifiedString = [regex stringByReplacingMatchesInString:text
options:0
range:NSMakeRange(0, [text length])
withTemplate:@""];
return modifiedString;
}

最后

以上就是秀丽胡萝卜为你收集整理的IOS程序开发之禁止输入表情符号实例代码的全部内容,希望文章能够帮你解决IOS程序开发之禁止输入表情符号实例代码所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(144)

评论列表共有 0 条评论

立即
投稿
返回
顶部