Is this even possible?
I want to select/mark text without text view becoming first responder. I have search implemented in UIPopoverController
and then when it's dismissed UIToolBar
with Next and Previous button is showed which allows me to select next or previous result and I see that text is being selected because UITextView scrolls down and up respectively but I don't see any selection color or text that's actually selected, just plain black on white.
If it is first responder than everything is working but that's not behavior that I'm trying to achieve.
Any hints?
Tnx for help
If you're working on iOS 6 environment, you can use the attributedText
property if UITextView
.
If you're working below iOS 6, try using EGOTextView, it's a drop-in replacement with rich text editing, it haven't been supported for a year or so, so I don't really know if it'll work.
You should determine a range for which you'll apply the changes
NSRange range = [textView.text rangeOfString:searchString];
Then create the attributed string
NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:textView.text];
[attrStr addAttribute:NSBackgroundColorAttributeName value:[UIColor cyanColor] range:range];
textView.attributedText = attrStr;