iOS中UITextView方法解讀

iOS中UITextView方法解讀

經常使用屬性解讀:
字體

@property(nonatomic,assignid<UITextViewDelegate> delegate;atom

設置代理屬性
spa

@property(nonatomic,copyNSString *text;.net

textView上的文本代理

@property(nonatomic,retainUIFont *font;code

設置文本字體
orm

@property(nonatomic,retainUIColor *textColor;blog

設置文本顏色
ci

@property(nonatomicNSTextAlignment textAlignment; 字符串

設置文本對齊模式

@property(nonatomicNSRange selectedRange;

設置選中的文本範圍(只有當textView是第一響應時纔有效)

@property(nonatomic,getter=isEditable) BOOL editable;

設置是否能夠編輯

@property(nonatomic,getter=isSelectable) BOOL selectable;

設置是否能夠選中


@property(nonatomicUIDataDetectorTypes dataDetectorTypes;

這個屬性能夠將本文中的電話,郵件等變爲連接,長按會調用響應響應的程序(textView必須爲不可編輯狀態),屬性的枚舉以下:

?

1
2
3
4
5
6
7
8
typedef  NS_OPTIONS(NSUInteger, UIDataDetectorTypes) {
     UIDataDetectorTypePhoneNumber   = 1 << 0,           // 電話變爲連接
     UIDataDetectorTypeLink          = 1 << 1,           // 網址變爲連接   
     UIDataDetectorTypeAddress       = 1 << 2,           // 地址變爲連接
     UIDataDetectorTypeCalendarEvent = 1 << 3,           // 日曆變爲連接
     UIDataDetectorTypeNone          = 0,                // 無鏈接
     UIDataDetectorTypeAll           = NSUIntegerMax     // 全部類型連接
};

@property(nonatomicBOOL allowsEditingTextAttributes;

設置是否容許編輯屬性字符串文本

@property(nonatomic,copyNSAttributedString *attributedText;

設置屬性字符串文本

@property(nonatomic,copyNSDictionary *typingAttributes;

設置屬性字符串文本屬性字典


- (void)scrollRangeToVisible:(NSRange)range;

滾動textView使其顯示在本一段文本

@property (readwriteretainUIView *inputView;  

設置成爲第一響應時彈出的視圖,鍵盤視圖

@property (readwriteretainUIView *inputAccessoryView;

設置成爲第一響應時彈出的副視圖,副鍵盤視圖

@property(nonatomicBOOL clearsOnInsertion;

設置是否顯示刪除按鈕


UITextViewDelegate中的方法

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView;

是否開始編輯

- (BOOL)textViewShouldEndEditing:(UITextView *)textView;

是否結束編輯

- (void)textViewDidBeginEditing:(UITextView *)textView;

開始編輯時觸發的方法

- (void)textViewDidEndEditing:(UITextView *)textView;

結束編輯時觸發的方法

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text;

是否容許字符改變

- (void)textViewDidChange:(UITextView *)textView;

字符內容改變觸發的方法

- (void)textViewDidChangeSelection:(UITextView *)textView;

選中內容改變觸發的方法

- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange;

當文本中的URL進行連接時觸發的方法

相關文章
相關標籤/搜索