Underline text inside uitextview

橙三吉。 提交于 2019-12-31 06:56:06

问题


How can i underline text inside uitextview programmatically?


回答1:


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?




回答2:


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];



回答3:


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];


来源:https://stackoverflow.com/questions/10309609/underline-text-inside-uitextview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!