Search code examples
iosobjective-cuikitnsattributedstringdtcoretext

How do I make DTCoreText use the System Font?


I want to use DTCoreText in my app to convert HTML to NSAttributedString, but I can't figure out how to use the system font (as of iOS 8: Helvetica Neue) as the base font. By default DTCoreText seems to create the NSAttributedString with the Times New Roman font.

I'd really prefer not to hardcode it. If Apple updates their font again (they previously updated it from Helvetica to Helvetica Neue) I don't want to replace all instances of it, or have a bunch of conditionals depending on the OS version running the code.

I tried:

NSDictionary *options = @{
   DTUseiOS6Attributes: @(YES),
   DTDefaultFontFamily: [UIFont systemFontOfSize:[UIFont systemFontSize]].fontName
};

But it still renders as Times New Roman.

How do I make it use the system font? I just want it to look normal.


Solution

  • Looks like DCCoreText is expecting to receive font family name, and you're providing font name which is different. Try to replace your code with

    [UIFont systemFontOfSize:[UIFont systemFontSize]].familyName