how to give background color for selected text in

2019-02-24 13:54发布

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?

2条回答
欢心
2楼-- · 2019-02-24 13:55

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.).

查看更多
做个烂人
3楼-- · 2019-02-24 14:09

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.

查看更多
登录 后发表回答