How to change the color of the iOS autocorrect suggestion?

风格不统一 提交于 2019-11-30 03:49:07

问题


After much searching here and on the web and in developer forums, I can't believe that nobody seems to have even asked this question before.

The iOS autocorrect suggestions always popup with a blue font on a white background, regardless of the colors of your UITextField or UITextView or anything else. This looks pretty bad sometimes, e.g. on a dark background. It seems bizarre that it would adopt the font of the text you're editing, but have no way to change the default colors.

And yet in the built-in iOS Notes app, the autocorrect suggestions appear beautifully with a yellow background and red font.

Am I missing something obvious here?


回答1:


The UITextInput protocol defines a method - (NSDictionary *)textStylingAtPosition:(UITextPosition *)position inDirection:(UITextStorageDirection)direction which the docs claim can be used to style correction rectangles. I gather this would be communicated through a UITextPosition subclass that indicates styling information is being requested, but I'm not sure on the details of that. Something to look more into for sure!

EDIT:

I just implemented a UITextField and a UITextView subclass and overrode the below method. The method was never called :( Sorry to answer with false hope!

EDIT 2: found a blog post explaining why it was never called: http://bjhomer.blogspot.com/2011/11/detecting-backspace-in-uitextfield.html



来源:https://stackoverflow.com/questions/12172006/how-to-change-the-color-of-the-ios-autocorrect-suggestion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!