views:

260

answers:

1

how to give background color for selected text in text view ? hi, Im developing text view based app. in that i have to change color for selected text. i tried using delegate methods but i not found any property like this. if any iahve any ideas , suggestions how to overcome this issue.

thanks in advance

A: 

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

KennyTM
thanks for reply.yes i know there is no way to change the background color in text view for selected text. But my requirement is like above. So please forward me suggestions how to resolve my requirement.
maddy
@madhu: "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."
KennyTM
@KennyTm "yes thank you, i am trying this but how to calculate rectangles when text view in edit mode"
maddy
@madhu: Calculate the bounds of each character by `-sizeWithFont:`, and accumulate them until to reach the end of selection. (All simple ways resort to undocumented methods.)
KennyTM