UITextView+LengthLimit.h 1.33 KB
//
//  UITextView+LengthLimit.h
//  Gengmei
//
//  Created by wangyang on 2017/3/9.
//  Copyright © 2017年 更美互动信息科技有限公司. All rights reserved.
//

#import <UIKit/UIKit.h>

/**
 UITextView 输入之字数限制. http://blog.csdn.net/fengsh998/article/details/45421107
 */
@interface UITextView (LimitBase)
@property(nonatomic, assign) NSInteger maxTextLength;
@property(nonatomic, readonly, assign) NSInteger textLength;
@end


@interface UITextView (SimpleLimit)

/**
 对字数进行简单限制。该方法可以就对绝大部分需求。例如需求只限制最大长度,没有提示性交互,没有特殊字符过滤时,使用该方法即可以
 
 在 UITextViewDelegate textViewDidChange中调用
 */
- (void)s_textViewDidChange;
@end

@interface UITextView (ComplexLimit)
/**
 对字数进行复杂限制。如果需求有在输入时的交互提示,有特殊字符过滤时,需要使用下面方法。需要配合 c_textViewDidChange 同时使用

 在 UITextViewDelegate textView:shouldChangeTextInRange:replacementText: 调用并返回
 */
- (BOOL)c_shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text;

/**
 对字数进行复杂限制。需要配合 c_shouldChangeTextInRange:replacementText 同时使用

 在 UITextViewDelegate textViewDidChange中调用
 */
- (void)c_textViewDidChange;

@end