How can I underline text in iOS 6?

前端 未结 2 1781
无人及你
无人及你 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;
    

提交回复
热议问题