UITextView linkTextAttributes font attribute not applied to NSAttributedString

后端 未结 8 662
暖寄归人
暖寄归人 2021-02-01 20:18

I have an NSAttributedString generated from HTML which includes some links. The attributed string is shown in a UITextView. I wish to apply a different font style f

8条回答
  •  情歌与酒
    2021-02-01 20:58

    There's also an easy way to apply style for the text if you use html - you can just add the style within the html code. Then you wouldn't need to worry about setting attributes for the text. For example:

    NSString *html = [NSString stringWithFormat:@"

    %@ %@ on %@

    ", name, taskName, timeString]; NSDictionary *options = @{NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType}; NSData *data = [html dataUsingEncoding:NSUTF8StringEncoding]; NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:data options:options documentAttributes:nil error:nil];

提交回复
热议问题