0

I am looking for all the text in my text view to be gray and then the first sentence to be black. How do I set that range to black. I already have the first sentence string/range. Thank You.

    [tv setTextColor:[UIColor grayColor]];

    id<UITextInputTokenizer> tokenizer = tv.tokenizer;
    UITextRange *range = [tokenizer rangeEnclosingPosition:tv.beginningOfDocument
                                           withGranularity:UITextGranularitySentence
                                               inDirection:UITextStorageDirectionForward];
    NSString *firstSentence = [tv textInRange:range];
    NSLog(@"%@",firstSentence);
BDGapps
  • 3,318
  • 10
  • 56
  • 75

1 Answers1

0

Not much good news to offer here. You want an NSAttributed string, but that's not available as the model of the standard text view. I haven't checked this out personally, but there's some web code that might help referenced here...

Community
  • 1
  • 1
danh
  • 62,181
  • 10
  • 95
  • 136
  • could i make a custom font that has a color? – BDGapps Jul 28 '12 at 18:00
  • can i put a cgrect around it? If so how would i go about this. – BDGapps Jul 28 '12 at 18:08
  • i think i see what you're thinking - put a view in front of the text and use that to alter the color? the hitch is that there's no predicting how some arbitrary text will get word-wrapped. the only method you have available is NSString sizeWithFont:. If you knew, say, that the sentence was always at the start of the text view, then you could add a subview to the text view at roughly 0,0 and size it with the sizeWithFont:. Then set it's background color. But it's not very general. Kind of stinks that iOS doesn't give us a text view with rich text control. – danh Jul 28 '12 at 18:49
  • about your first question - you can set the textColor for the view, but it will apply to all of the text in the view. – danh Jul 28 '12 at 18:52