How can I underline text in iOS 6?

前端 未结 2 1758
无人及你
无人及你 2021-01-12 01:22

I am trying to underline some text in a label. However, I do\'t know how to get the range of the entire text in the label. This is what I have so far:

NSMuta         


        
相关标签:
2条回答
  • 2021-01-12 01:54
    NSMutableAttributedString *attributedString =[[NSMutableAttributedString alloc] initWithString:strComplete];
    
    [attributedString addAttribute:NSUnderlineStyleAttributeName
                             value:@(NSUnderlineStyleSingle)
                             range:[strComplete rangeOfString:strFirst]];
    
    [attributedString addAttribute:NSForegroundColorAttributeName
                             value:[UIColor redColor]
                             range:[strComplete rangeOfString:strSecond]];
    
    
    cell.textLabel.attributedText = attributedString;
    
    0 讨论(0)
  • 2021-01-12 01:58

    For the range you may want to use:

    NSMakeRange (0, mat.length);
    

    Like this:

    NSMutableAttributedString *mat = [self.tableLabel.attributedText mutableCopy];
    [mat addAttributes:@{NSUnderlineStyleAttributeName: @(NSUnderlineStyleSingle)} range:NSMakeRange (0, mat.length)];
    self.tableLabel.attributedText = mat;
    
    0 讨论(0)
提交回复
热议问题