2009-12-03 123 views
6

是否可以重寫UITextView中的遊標和自動更正氣泡的顏色?這是在內置的Notes應用程序中完成的,但我不知道它是否通過公共手段完成。你可以改變UITextView中的光標顏色嗎?

我找不到任何文檔中的任何引用,所以我擔心它是在UIKeyboard中設置的私有API或其他東西。我錯過了明顯的東西嗎?

+4

注意,未來的人:這在iOS 7中很容易。它只是文本視圖的tintColor。 2009年的情況並非如此簡單。 – 2014-05-19 19:17:43

回答

7

儘管這個問題已經在這裏找到答案是UITextInputTraits(在iOS5的測試和6b :) 我認爲人們閱讀一些這方面的了不起(讀私立)方法的目標不是AppStore的:p

其中一些是:

UITextInputTraits *inputTraits = [_textView textInputTraits]; 
UIColor *purpleColor = [UIColor purpleColor]; 
[inputTraits setInsertionPointColor:purpleColor]; 
[inputTraits setInsertionPointWidth:1]; // Read below note 
[inputTraits setSelectionHighlightColor:[purpleColor colorWithAlphaComponent:0.1]]; 
[inputTraits setSelectionDragDotImage:[UIImage imageNamed:@"CoolHandle"]]; 
[inputTraits setSelectionBarColor:purple]; 

insertionPointWidth:顯然沒有任何效果。您需要在UITextView子類中覆蓋caretRectForPosition:(方法UITextInput協議)。

結果:

Almost lickable


此外,這些很有意思:

[inputTraits setAcceptsFloatingKeyboard:NO]; 
[inputTraits setAcceptsSplitKeyboard:NO]; 

使用這些過去兩年精心因爲其他文本視圖/域可以接受的浮動或拆分鍵盤和鍵盤可能無法正確更新當你的textview與定製輸入特性becom第一響應者。

爲了得到一個完整的方法列表:

- (void)printMethodsOfClass:(Class)class 
{ 
    unsigned int methodCount = 0; 
    NSLog(@"%@", NSStringFromClass(class)); 
    Method *mlist = class_copyMethodList(class, &methodCount); 
    for (int i = 0; i < methodCount; ++i){ 
     NSLog(@"%@", NSStringFromSelector(method_getName(mlist[i]))); 
    } 
    NSLog(@"------------------------------------------------------------"); 
    free(mlist); 
} 

[self printMethodsOfClass:[[textview textInputTraits] class]]; 
3

在iOS 7+這是現在通過設置您的文本字段tintColor屬性完成的。

+0

我們如何設置IOS 6的光標顏色? – 2014-07-14 06:21:51

+0

我不知道在iOS 6上支持的方式。 – 2014-07-14 17:52:50

+0

@jeffamaphone感謝您的回覆..我正在使用代碼[[textField valueForKey:@「textInputTraits」] setValue:[UIColor redColor] forKey:@「insertionPointColor」 ]。對於iOS 6.你可以讓我知道,使用此代碼我的應用程序將批准在App Store發佈謝謝! – 2014-07-14 19:07:13

相關問題