是否可以重寫UITextView中的遊標和自動更正氣泡的顏色?這是在內置的Notes應用程序中完成的,但我不知道它是否通過公共手段完成。你可以改變UITextView中的光標顏色嗎?
我找不到任何文檔中的任何引用,所以我擔心它是在UIKeyboard中設置的私有API或其他東西。我錯過了明顯的東西嗎?
是否可以重寫UITextView中的遊標和自動更正氣泡的顏色?這是在內置的Notes應用程序中完成的,但我不知道它是否通過公共手段完成。你可以改變UITextView中的光標顏色嗎?
我找不到任何文檔中的任何引用,所以我擔心它是在UIKeyboard中設置的私有API或其他東西。我錯過了明顯的東西嗎?
儘管這個問題已經在這裏找到答案是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
協議)。
[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]];
我發現這個鏈接描述了「隱藏」UIKeyboard
魔法。看起來像UITextTraits
有一個CaretColor
屬性。可悲的是,我不認爲這會讓蘋果的審查過程變得麻煩。除非他們沒有注意到?這是可能的...
http://ericasadun.com/iPhoneDocs112/interface_u_i_keyboard.html
在iOS 7+這是現在通過設置您的文本字段tintColor
屬性完成的。
我們如何設置IOS 6的光標顏色? – 2014-07-14 06:21:51
我不知道在iOS 6上支持的方式。 – 2014-07-14 17:52:50
@jeffamaphone感謝您的回覆..我正在使用代碼[[textField valueForKey:@「textInputTraits」] setValue:[UIColor redColor] forKey:@「insertionPointColor」 ]。對於iOS 6.你可以讓我知道,使用此代碼我的應用程序將批准在App Store發佈謝謝! – 2014-07-14 19:07:13
注意,未來的人:這在iOS 7中很容易。它只是文本視圖的tintColor。 2009年的情況並非如此簡單。 – 2014-05-19 19:17:43