Can you change the color of the cursor in a UITextView?

Is it possible to override the cursor color and auto-correction in UITextView? This is done in the built-in Notes application, but I don’t know if it was made publicly available or not.

I cannot find references to this in any documentation, so I am worried that this is a private API installed in UIKeyboard or something like that. Am I missing something?

+6
iphone uikit
source share
3 answers

Although this question has already been answered, there are some awesome (read private) UITextInputTraits methods (tested on iOS5 and 6b :) I assume that people reading this do not target the AppStore: p

Some of them:

 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: seems to have no effect. You need to override caretRectForPosition: (protocol method UITextInput ) in a subclass of UITextView .

Result:

Almost lickable


They are also interesting:

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

Use these last two, because other text views / fields may accept floating or split keyboards, and the keyboard may not update correctly when your text with custom input features becomes the first responder.

To get a complete list of methods:

 - (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]]; 
+7
source share

On iOS 7+, this is accomplished by setting the tintColor property in the text box.

+3
source share

I found this link that described the “hidden” magic of UIKeyboard . It looks like UITextTraits has the CaretColor property. Unfortunately, I don't think that messing with this would be through the Apple review process. Didn’t they notice? It is possible ...

http://ericasadun.com/iPhoneDocs112/interface_u_i_keyboard.html

+1
source share

All Articles