Underline text inside uitextview

前端 未结 3 1897
野的像风
野的像风 2021-01-27 09:01

How can i underline text inside uitextview programmatically?

相关标签:
3条回答
  • 2021-01-27 09:07
    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];
    
    0 讨论(0)
  • 2021-01-27 09:11

    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?

    0 讨论(0)
  • 2021-01-27 09:28

    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];
    
    0 讨论(0)
提交回复
热议问题