how to give background color for selected text in text view

妖精的绣舞 提交于 2019-12-20 02:14:37

问题


How can I give a background color for selected text in text view?

I'm developing text view based app and I have to change the color for selected text.

I tried using delegate methods but I haven't found any property like this. Can you please suggest a way to overcome this issue?


回答1:


There is no way to change the selection color within AppStore limitation. In fact, considering MobileNotes.app's selection background color is also light blue despite the caret is brown, we can see that Apple doesn't intend to allow non-blue selection background color.

However, you can calculate the rectangles occupied by the selection, then make a colored transparent non-interacting UIView on top of it to simulate a change of background color.


You can change the selection color globally (within your app) by overriding the undocumented method +[UIColor selectionTintColor] (e.g. using method_setImplementation, etc.).




回答2:


Resolved issue by using own logic like.

Using

  • (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

  • (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

Calculated the Area of framing which i want to add color of text and on tapping on done creating a custom view and drawing text on it with selected range of tetx in different color and remaining normally. and it is go on... I am maintaining all values in XML file to read/edit the data.

When we want to edit the text data removing the custom view and when we resign the textView adding custom view with exisitng values from XML file. Its Works as usual expected.

Thanks for all your support to resolve the issue.



来源:https://stackoverflow.com/questions/2183275/how-to-give-background-color-for-selected-text-in-text-view

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