【发布时间】:2012-04-25 05:03:51
【问题描述】:
如何以编程方式在 uitextview 中为文本添加下划线?
【问题讨论】:
-
我在使用 NSForegroundColorAttributeName 时遇到未声明的错误。请告诉我
标签: ios ios4 uitextview
如何以编程方式在 uitextview 中为文本添加下划线?
【问题讨论】:
标签: ios ios4 uitextview
您可以为此目的使用 NSAttributedString。 以下是相同的链接 - https://github.com/AliSoftware/Ali-Cocoa-Classes
你可以参考这个线程来检查如何使用 NSAttributedString。 How do you use NSAttributedString?
【讨论】:
我使用 UIWebView 而不是 UITextView 来解决这个问题。
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];
【讨论】:
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];
【讨论】: