Add Custom Font in a Cocoa Application

Apple didn't document well about how to customize the font in a Cocoa application. And here is my note while writing a digital clock application for Ling.

First of all, add the font file to Xcode and make sure that file is marked as a member of the application.

Secondly, add an entry that specifies the path to your custom font(s). By default, the custom font will be placed right under Resources directory of the application. Thus we can add the following entry to Info.plist


Finally, the custom font can be used in your application.

let textFontAttributes = [
    .font: NSFont(name: "digital-7", size: 63)!,
    .foregroundColor: clockColor,
    .paragraphStyle: textStyle,
    ] as [NSAttributedString.Key: Any]
声明: 本文为0xBBC原创, 转载注明出处喵~

Leave a Reply

Your email address will not be published. Required fields are marked *