NSString *text = @"Privacy Policy.";
NSMutableAttributedString * attributedText = [[NSMutableAttributedString alloc] initWithString: text];
NSRange range = NSMakeRange(0, [attributedText length]);
[attributedText beginEditing];
// next make the text appear with an underline
NSRange underLineRange = range;
range.length -= 1;
[attributedText addAttribute: NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:NSSingleUnderlineStyle] range:underLineRange];
[attributedText addAttribute:NSFontAttributeName value:PRDefaultFontWithSize(NO, 12) range:range];
[attributedText addAttribute:NSForegroundColorAttributeName value:[NSColor colorWithDeviceRed:237/255.0 green:187/255.0 blue:112/255.0 alpha:1] range:underLineRange];
[attributedText addAttribute:NSForegroundColorAttributeName value:[NSColor colorWithDeviceRed:128/255.0 green:128/255.0 blue:128/255.0 alpha:1]range:NSMakeRange([attributedText length]-1, 1)];
[attributedText endEditing];
本文介绍如何使用NSAttributedString为文本添加下划线、字体、颜色等样式,包括详细的代码实现过程。
551

被折叠的 条评论
为什么被折叠?



