字体解析问题

Issue with font parsing

如果有人能帮助我解决问题,我将不胜感激。我需要从我得到的 html 字符串中获取一个属性字符串,其中包含没有字体样式或大小的文本模式。我其实想把我特定的字体大小和样式选项放到那段文字中。

<body>
<div>No font style <span style="font-size: 14px;"><span style="font-family: verdana, helvetica, sans-serif;">And verdana 14  <span style="font-size: 18px;">And Verdana 18</span></span></span></div>

NSAttributedString* attrStr = [[NSAttributedString alloc] initWithData:[html dataUsingEncoding:NSUTF8StringEncoding] options:@{...}     documentAttributes:nil error:&error];

请尝试

NSMutableString *formattedContentString = [NSMutableString stringWithFormat:@"<style>*{font-family:%@;} !important</style> %@", @"Helvetica", htmlString];

更新:

NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:contentString
attributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"Your Font" size:20], NSFontAttributeName, nil]];