#pragma - mark
@class UIFont, UIColor, UITextView, NSTextContainer, NSLayoutManager, NSTextStorage, NSTextAttachment;
#pragma - mark - 代理
@protocol UITextViewDelegate
@optional
// 是否能够开始编辑
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView;
// 是否结束编辑
- (BOOL)textViewShouldEndEditing:(UITextView *)textView;
// 已经开始编辑
- (void)textViewDidBeginEditing:(UITextView *)textView;
// 已经结束编辑
- (void)textViewDidEndEditing:(UITextView *)textView;
// 是否能够修改替换range范围内的文字
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text;
// 选择发生变化是调用
- (void)textViewDidChange:(UITextView *)textView;
// 改变选择的的文字
- (void)textViewDidChangeSelection:(UITextView *)textView;
// 是否跳转URL连接
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange NS_AVAILABLE_IOS(7_0);
// 是否相应附件的点击
- (BOOL)textView:(UITextView *)textView shouldInteractWithTextAttachment:(NSTextAttachment *)textAttachment inRange:(NSRange)characterRange NS_AVAILABLE_IOS(7_0);
@end
NS_CLASS_AVAILABLE_IOS(2_0) @interface UITextView : UIScrollView
@property(nonatomic,assign) id delegate;
@property(nonatomic,copy) NSString *text; // 文本内容
@property(nonatomic,retain) UIFont *font; // 文本的字体
@property(nonatomic,retain) UIColor *textColor; // 文本的颜色
@property(nonatomic) NSTextAlignment textAlignment; // 默认左对齐
@property(nonatomic) NSRange selectedRange; //
@property(nonatomic,getter=isEditable) BOOL editable; // 是否能被编辑
@property(nonatomic,getter=isSelectable) BOOL selectable NS_AVAILABLE_IOS(7_0); // 控制用户能否选择文本内容和能否点击文本的URLs toggle selectability, which controls the ability of the user to select content and interact with URLs & attachments
@property(nonatomic) UIDataDetectorTypes dataDetectorTypes NS_AVAILABLE_IOS(3_0);
@property(nonatomic) BOOL allowsEditingTextAttributes NS_AVAILABLE_IOS(6_0); // 是否允许编辑本文
@property(nonatomic,copy) NSAttributedString *attributedText NS_AVAILABLE_IOS(6_0); // default is nil
@property(nonatomic,copy) NSDictionary *typingAttributes NS_AVAILABLE_IOS(6_0); // automatically resets when the selection changes
- (void)scrollRangeToVisible:(NSRange)range;
@property (readwrite, retain) UIView *inputView; // 输入框
@property (readwrite, retain) UIView *inputAccessoryView; // 输入框附件(输入框上面44高度的view)
@property(nonatomic) BOOL clearsOnInsertion NS_AVAILABLE_IOS(6_0); // defaults to NO. if YES, the selection UI is hidden, and inserting text will replace the contents of the field. changing the selection will automatically set this to NO.
// Create a new text view with the specified text container (can be nil) - this is the new designated initializer for this class
- (instancetype)initWithFrame:(CGRect)frame textContainer:(NSTextContainer *)textContainer NS_AVAILABLE_IOS(7_0);
// Get the text container for the text view
@property(nonatomic,readonly) NSTextContainer *textContainer NS_AVAILABLE_IOS(7_0);
// Inset the text container's layout area within the text view's content area
@property(nonatomic, assign) UIEdgeInsets textContainerInset NS_AVAILABLE_IOS(7_0);
// Convenience accessors (access through the text container)
@property(nonatomic,readonly) NSLayoutManager *layoutManager NS_AVAILABLE_IOS(7_0);
@property(nonatomic,readonly,retain) NSTextStorage *textStorage NS_AVAILABLE_IOS(7_0);
// Style for links
@property(nonatomic, copy) NSDictionary *linkTextAttributes NS_AVAILABLE_IOS(7_0);
@end
// 文本框开始编辑通知
UIKIT_EXTERN NSString * const UITextViewTextDidBeginEditingNotification;
UIKIT_EXTERN NSString * const UITextViewTextDidChangeNotification;
UIKIT_EXTERN NSString * const UITextViewTextDidEndEditingNotification;