Is it possible to override the color of the cursor and autocorrection bubbles in a UITextView? This is done in the built-in Notes application, but I don't know if it was done by public means or not.
I can't find any reference to this in any documentation, so I'm worried that it's a private API set in the UIKeyboard or something. Am I missing something obvious?
Although this question is already answered here are some terrific (read private) methods of UITextInputTraits
(tested in iOS5 and 6b :)
I assume people reading this are not targeting the 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:
apparently has no effect. You need to override caretRectForPosition:
(method of UITextInput
protocol) in your UITextView
subclass.
[inputTraits setAcceptsFloatingKeyboard:NO];
[inputTraits setAcceptsSplitKeyboard:NO];
Use these last two carefully because other text views/fields could accept floating or split keyboards and the keyboard might not update correctly when your textview with the customized input traits becomes the first responder.
- (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]];
On iOS 7+ this is now accomplished by setting the tintColor
property on your text field.
I found this link that described the "hidden" UIKeyboard
magic. Looks like UITextTraits
has a CaretColor
property. Sadly, I don't think messing with this would make it through Apple's review process. Unless they didn't notice? It's possible...
http://ericasadun.com/iPhoneDocs112/interface_u_i_keyboard.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With