AOY
AOY

Reputation: 355

Issue with font parsing

I would really appreciate if anyone could help me to solve an issue. I need to get an attributes string from the html string I've got which contains text patterns without font style or size. I actually want to put my specific font size and style options to that piece of text.

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

Upvotes: 0

Views: 43

Answers (1)

Vũ Ngọc Giang
Vũ Ngọc Giang

Reputation: 234

Please try

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

Update:

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

Upvotes: 1

Related Questions