更新时间:2023-02-16 17:09:38
您可以使用 NSAttributedString
如下所示。
NSMutableAttributedString* string = [[NSMutableAttributedString alloc]initWithString:@"you string"];
[string addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, string.length)];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(0, string.length)];//TextColor
[string addAttribute:NSUnderlineStyleAttributeName value:underlineNumber range:NSMakeRange(0, string.length)];//Underline color
[string addAttribute:NSUnderlineColorAttributeName value:[UIColor lightGrayColor] range:NSMakeRange(0, string.length)];//TextColor
yourlabel. attributedText = string;
注意:您还可以将特定范围的字符串加下划线为喜欢这篇文章。另请注意,它仅适用于ios6 +。
Note: You can also underline particular range of string as like in this post. Also note down, it works ios6+ only.