NSMutableAttributedString 的使用方法,设置格式

NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:title];
    NSRange range = NSMakeRange(0, [attrString length]);
    
    [attrString beginEditing];
    [attrString addAttribute:NSLinkAttributeName value:aURL range:range];
    
    // make the text appear in blue
    [attrString addAttribute:NSForegroundColorAttributeName value:[NSColor blueColor] range:range];
    
    // next make the text appear with an underline
    [attrString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSSingleUnderlineStyle] range:range];
    
    // allow truncation
    NSMutableParagraphStyle *ps = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
    [ps setLineBreakMode:NSLineBreakByTruncatingTail];
    [attrString addAttribute:NSParagraphStyleAttributeName value:ps range:range];
    [ps release];
    
    [attrString endEditing];
    
    return [attrString autorelease];    

转载自:http://blog.csdn.net/ch_soft/article/details/6877508

posted @ 2014-05-16 11:30  Dadada胖纸er  阅读(401)  评论(0编辑  收藏  举报