0

How can i underline text inside uitextview programmatically?

Martin G
  • 16,009
  • 9
  • 78
  • 91
user198725878
  • 6,076
  • 16
  • 74
  • 134

3 Answers3

0

You can use NSAttributedString for this purpose. Following is link for the same - https://github.com/AliSoftware/Ali-Cocoa-Classes

And you can refer this thread to check how to use NSAttributedString. How do you use NSAttributedString?

Community
  • 1
  • 1
rishi
  • 11,622
  • 4
  • 39
  • 58
0

I used UIWebView instead of UITextView to solve this problem.

NSString *contentHtml = [NSString stringWithFormat:@"<html><head></head><body><font color=\"white\" size=\"4\"><table width=\"260px\"><tr><td align=\"left\" width=\"160px\"><u>Left:</u></td><td align=\"right\" width=\"100px\">315</td></tr></table></font></body></html>"];
[listWebView loadHTMLString:contentHtml baseURL:nil];
irmu
  • 1,166
  • 2
  • 12
  • 21
0
NSMutableAttributedString *attributedString = [self.textView.attributedText mutableCopy];   
int valueToSet = kCTUnderlineStyleSingle;
[attributedString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:valueToSet] range:CGMakeRange(0, self.textView.text.length)];

self.textView.attributedText = attributedString;
[attributedString release];
Nishchith Cp
  • 51
  • 1
  • 2