简体   繁体   中英

UILabel detect userName from HTML text and change its font color?

I am getting following text from server.

"<span class='quill-mention' data-name='@Saurabh Shah
 (5327)' data-id='859155' user-id='859155'>@Saurabh Shah
 (5327)</span>  Test";

I want to make it like @Saurabh Shah Test

With @Saurabh Shah as Blue color font.

Currently I am using following code :

        NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithData:
                                            [self.message dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: [NSNumber numberWithInt:NSUTF8StringEncoding]} documentAttributes:nil error:nil];

That gives me string : @Saurabh Shah Test. But not blue color.

How can i do it?

尝试在您的选项中使用它:NSForegroundColorAttributeName

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM