You can use the WebPreferences object to control the font used to create the attribute string from HTML.
The -initWithHTML:options:documentAttributes: method -initWithHTML:options:documentAttributes: dictionary. One of the recognized keys for this dictionary is NSWebPreferencesDocumentOption . The value is an instance of WebPreferences that will be used when interpreting HTML.
A WebPreferences instance has several font family settings. One that is used when no other font attributes are specified in the HTML is -standardFontFamily . If HTML defines a font class (for example, "sans-serif") but does not have a specific font, then the settings for that font class are used (for example, -sansSerifFontFamily ).
WebPreferences also has font size settings.
For instance:
WebPreferences *webPreferences = [[WebPreferences alloc] initWithIdentifier:@"com.company.app.something"]; webPreferences.standardFontFamily = [someFont familyName];
There is a caveat: the system font has a family that is hidden from WebPreferences / NSAttributedString . On the Mavericks, his name is ".Lucida Grande UI"; on Yosemite, its name is ". Helvetica Neue UI." For some reason, they cannot be used when converting HTML to an attribute string using the WebPreferences object. My best guess is because they are not listed in [[NSFontManager sharedFontManager] availableFontFamilies] . When you try to use such a font family, the system uses Times (yuck!) By default.
source share