ch_soft的专栏

我,只专注于移动互联网,技术交流群:10912272

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];    

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ch_soft/article/details/6877508
个人分类: 【开发技术】MAC
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭