Skip navigation

Adding a Dotted red line under characters in a UITextView

437 Views 2 Replies Latest reply: Nov 19, 2012 11:11 AM by araghur RSS
araghur Calculating status...
Currently Being Moderated
Nov 19, 2012 8:50 AM

I am trying to create my custom spell checker for the UITextView.

To show that a word is misspelled, I need to add the "red dotted line" under the misspelled word. To do that, here is what I thought would work -

I create a dictionary which contains the values for the key NSUnderlineStyleAttributeName. However, what this does is, it does underline the characters but it does not have a dotted pattern. Also, setting the strokeColorAttribute also does not seem to have any effect.

Here is my code -

NSMutableDictionary *misspelledAttributes = [NSMutableDictionary dictionary];

[misspelledAttributes setObject:[NSNumber numberWithInt:kCTUnderlineStyleThick|kCTUnderlinePatternDot] forKey:NSUnderlineStyleAttributeName];

[misspelledAttributes setObject:[UIColor redColor] forKey:NSStrokeColorAttributeName];

To set the attributes to a attributed string for a particular range -

NSMutableAttributedString *attrString = [self.textView.attributedText mutableCopy];

[attrString addAttributes:misspelledAttributes range:wordRange];

self.textView.scrollEnabled = NO;

self.textView.attributedText = attrString;

self.textView.selectedRange = NSMakeRange(NSMaxRange(range), 0);

self.textView.scrollEnabled = YES;


More Like This

  • Retrieving data ...

Bookmarked By (0)


  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.