0

I was wondering if it was possible to hide a particular word or expression from the text in a UITextView. If for example:

UITextView* txt = @"hello how are you"

Is there any way to hide the "you" so that it is not visible to the user (considering that the user can't edit the txt, but is still part of the text, so that I can do txt.text to get the ehole string ?

Gabriel.Massana
  • 8,165
  • 6
  • 62
  • 81
user2014474
  • 1,117
  • 5
  • 19
  • 36
  • What is the end goal here? It is often easiest to write a convenience method that tacks text on, rather than trying to hide it from the user. For example, `- (NSString*)getExtendedText:(UITextView*)txtView { return [NSString stringWithFormat:@"%@ you", txtView.text]; }` – Mathew Feb 07 '13 at 21:58
  • You could always store the actual text in a string somewhere and correlate the text view's text based on a modified version of that. Why go through all the trouble forcing the view to contain the model, especially for small strings? – Metabble Feb 07 '13 at 22:13

1 Answers1

1

As of iOS 6.0, UITextView can work with NSAttributedStrings (see the attributedText property) and using attributed strings, you can change the color to be clear (or hidden). It'll still be selectable, though, and may show up when highlighted.

And because of that last sentence, I'm not sure if this is what you want.

You may also find some helpful hints in this related question.

Community
  • 1
  • 1
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • for iOS 5, you'll have to use some drop in library or open source solution, [like the one described in this related question](http://stackoverflow.com/questions/5550739/set-nsattributedstring-to-uitextview). – Michael Dautermann Feb 08 '13 at 19:59