How to use custom fonts in a mac application? - xcode

I try to use custom fonts in my swift app, but they don't load.
I copy the fonts.ttf in my resources folder, and I added the names in Info.plist under "Fonts provided by application " key.
I've try with "Application fonts resource path" key from .plist , but no results.
Here is the code I used to apply my font. I've try with : "MyFont.ttf" , and "MyFont"
#IBOutlet weak var label:NSTextField!
override func awakeFromNib() {
label.font = NSFont(name: "MyFont.ttf", size: 15)
}

As "Application fonts resource path" is now a string type in XCode 7.3.1 and I couldn't seem to find a way to use an Array for multiple fonts, I used "." in the Info.plist:
Application fonts resource path String .
and this seemed to work to pick up all my custom fonts in a Resources folder dynamically e.g. using Swift
labelText.font = NSFont(name: "DS-Digital", size: 48)
However, to see it in XCode design mode (to choose a font from drop-down menu), I needed to first add the font to Font Book.
However, Font Book was not required for the dynamic method to work :)

ATSApplicationFontsPath is for macOS:
ATSApplicationFontsPath (String - macOS) identifies the location of a
font file or directory of fonts in the bundle’s Resources directory.
If present, macOS activates the fonts at the specified path for use by
the bundled app. The fonts are activated only for the bundled app and
not for the system as a whole. The path itself should be specified as
a relative directory of the bundle’s Resources directory. For example,
if a directory of fonts was at the path
/Applications/MyApp.app/Contents/Resources/Stuff/MyFonts/, you should
specify the string Stuff/MyFonts/ for the value of this key.
macOS app Instructions:
Select your Xcode project in the project navigator
Select your
app target
Click the + button and to add a New Copy Files Phase
Select Resources for the destination
Under subpath specify the directory (e.g. Fonts) where your embedded fonts will be copied to within your application bundle's Resources directory.
Drag and drop the font files into the file list of the Copy Files build phase.
UIAppFonts is for iOS:
UIAppFonts (Array - iOS) Specifies any app-provided fonts that should
be made available through the normal mechanisms. Each item in the
array is a string containing the name of a font file (including
filename extension) that is located in the app’s bundle. The system
loads the specified fonts and makes them available for use by the app
when that app is run.
This key is supported in iOS 3.2 and later.

By directly setting the Application fonts resource path as my font file's name, I solved this problem by sheer luck.

For those whose font family is called something like My-Custom-Font-Family:
be aware that in code you should instantiate your custom font like this: NSFont(name: "MyCustomFontFamily-Bold", size: 20)
Spaces and "-" are ignored and font type is written after "-". I did not see this in any docs and spend a few hours trying to figure out wtf was wrong.
Also if you want to get list of all available fonts you can use this code
for font in NSFontManager.shared.availableFonts {
print(font)
}

First add the desired font you want to embed to your OSX app to your project:
Then click project > Info, then click the plus sign and add a new key "Application fonts resource path" and type the name of your fonts there creating an array of strings:
Now you can select custom font and the name of the font will show there, you still need to use the Font Book to make it available inside Xcode.

Try doing this from the interface builder, in the attributes inspector .

Related

Bundle custom fonts into macOS standalone application using Xcode

I am new to macOS standalone application development and I am working on fixing the issues in it. I am running with an issue where the custom fonts not getting applied to controls present in the application. I am using Xcode 11.3 in macOS Mojave 10.14
There is already a fonts folder added to the project which contains all the font files (.ttf) extension. I have referred the "fonts" folder using the key "Application fonts resource path" in the Info.plist file. Even after applying all these changes the controls are getting referred to system font instead of the embedded font.
Also, the custom fonts which are added to the project is not being shown in the Font dropdown list of Attribute inspector.
Can you please suggest on what needs to be done in order to embed the custom fonts into the project and also show these custom fonts in fonts dropdown list?
Install the font
On your macOS, double click on all the fonts you'd like to use. Following window will appear for each:
Click on the Install Font button.
Attributes inspector
You can now choose your font. Remember, only installed fonts are listed. Fonts bundled with your application are not. Select your custom font.
Bundle fonts
Add a new Copy Files phase
Set subpaths to Fonts
Drop all the font files there
Info.plist
Add a new row Application fonts resource path (ATSApplicationFontsPath)
Set value to Fonts (must match copy files phase subpath)
Test
How to test that fonts are bundled correctly:
Close the storyboard (Xcode)
Launch Font Book
Right click on your custom font and disable it
Launch your application and test that all the custom fonts are bundled properly and work as expected
Launch Font Book
Right click on your custom font and enable it again
WARNING
Do NOT open the storyboard file if you disable/remove your custom font.
You'll get the following warning if you do ...
... and all your custom font settings are gone. You can open the storyboard file again, but you have to enable/install your custom font.

How do I change icons for builtin actions in ckeditor?

How do I change the icons for builtin actions such as subscript, superscript bold and italic?
The documentation say that I have to place the icons in the images folder in my skin, but how do I know what the image should be called?
Also, ckeditor compiles the default images into one huge file, so do I need to rebuild that icon file(how?) after placing an icon.
I am using Ckeditor 4.
All skin icons must be included inside the icons folder in the skin folder. The icons file name must match the name of the icon files available in the icons folder of the plugins.
If you want the source version of your skin to overload icons properly, you must inform CKEditor about the presence of your custom icons. This is optional, but if not done your icons will be visible in the release version of your skin only. Check the skin.js file in the Moono skin for an example.
Try clearing the cache as well.
I've just downloaded CKEditor v4.5.7 basic edition and there is a "plugins" folder by default.
Are you sure about the version used ?
After edit :
Icons are defined in the file skins/moono/editor.css and for example for Bold look after class .cke_button__bold_icon - erverything can be changed there.
In order not to edit standard files, I suggest you to create a new skin : duplicate moono folder and rename as you like and in your config.js add
config.skin = 'skin-name';

xcode - Custom fonts on xcode do not appear on xib

I am trying to add new fonts on xcode5 to use them directly on xib file.
My fonts are 3 files. Kelson Sans Bold.otf Kelson Sans Light.otf and Kelson Sans Regular.otf).
I have:
-added files to my project
-edited my .plist adding a "Fonts provided by application" dictionary with 3 items with the complete name (with extention) of fonts files.
- added the files into /Library/fonts local directory
But in the interface new fonts do not appear.
I have missed something?
Tx in advance.
Fonts added to XCode5 does not work in Interface Builder. You have to set the font by code.
Something like:
textField.font =[UIFont fontWithName:#"Signika-Regular" size:size];
or using NSAttributedString

Icon for Action Extension in iOS8

I have worked on extensions and it's all very interesting. For all type of extensions, icons work really well except for Action Extension where the icon is all white? Do you know how to create an icon for Action Extension?
In the Build Phases of your Extension Settings, just add Images.xcassets (or the icon file) to the Copy Bundle Resources.
PS: For Action Icon, any color data in the image itself is ignored. via Apple Docs
The alpha channel of the image is used as a mask to generate the final
image that is presented to the user. Any color data in the image
itself is ignored.
I had to manually add my icon assets catalog in the build settings. I described it here:
To get this to work with my existing Asset Catalog, I had to add the following to the extension's Build Settings:
The name of the set in my Assets Catalog is "ExtIcon". I had tried setting the CFBundleIcon and the NSExtensionServiceToolbarIconFile keys in the info.plist for the extension, but had no luck. This actually seems to make sense since it is the same way that icon sets are linked to the container app, not via info.plist, but via the Build Settings.

Why isn't my iOS8 Application Action Extension App Icon showing up?

My app icon is just a grey super ellipse even though I have specified a icon asset catalog in my Targets App Icons and Launch Images.
The following worked for me creating a Share Extension, but I believe Action Extension will do the same. Note that in the case of an Action extension, you need a monochromatic version.
If you are using an asset catalog for your main application icon, you should be able to get the Extension to leverage that same asset catalog. The key for me was to:
Select my extension and tell it to use Asset Catalog. Select the same catalog your main icon is using. The default should be AppIcon
Select the image.xcassets file in XCode Project Navigator
Check my extension so that it is included in the Target Membership
Your asset catalog in your main application isn't accessible from your application extension as they are two separate applications bundles that can only share Frameworks.
You will need to create a separate asset catalog in your action extensions folder and reference that one in your Targets.
EDIT: This worked for me for iphone but not for ipad simulator. Making new images (60x60 and 76x76) with only black and white solved it.
Add the image.xcassets to the extension target

Resources