How to add a custom font to storyboard in Mac app development. I went through some blogs and tried by adding font book and develop one NStextfield using this custom font using storyboard. But it is system dependent. I created the DMG and install in another computer it uses the default font. I did it programmatically, but my requirement is through storyboard.
Please help me on this
I spent a bit of time trying to figure this out and found the solution in this related question.
In your info.plist file, which you made available to me at
It turns out you can safely get rid of the "Fonts Provided By Application" section (it's an iOS specific key and is ignored by macOS).
And for "Application Fonts resource path", make certain you have the font going into a "Fonts" folder (or some subfolder within your application bundle's Resources folder).
Lastly, do a custom copy build phase like this:
This is copying the font into the "Fonts" subfolder specified in your "Application Fonts resource path". You don't want the font in your Resources folder, but you do want it in a subfolder underneath Resources.
Related
Is the process for embedding a custom font different with Cocoa-AppleScript apps?
I have a label that would display a string in this custom font, but it is still defaulting to the system font when packaged and run on a mac that doesn't already have the font installed.
I've dragged the font (ConnectCode39.ttf) to the sidebar in Xcode, and ensured that the app is ticked under target membership.
I've even added Fonts provided by application - CCode39.ttf (The true name of the font, not the file) to the info.plist, although I'm not sure if I still need to do that with the latest Xcode?
I've confirmed that the .ttf file is in the 'Copy Bundled Resources' as well.
The label is currently set to use 'CCode39', although is this picking it up from my Mac's font library? If so, how do I change it to use the bundled copy of the font? Or is this part ok and there's something else I'm missing?
Thank you!
I'm currently translating my application (Mac OS X app) into another language. I've done almost all translations, but now I'm stuck on a pretty strange thing:
I have an additional window for the applications settings and translated the GUI elements the same way I did it for the main window. I imported the translations into my project which seemed to work fine because I can use the preview windows, switch the language of the assistant editor to German and see that the dialog will be localized correctly.
But as soon as I run my application (with "German" as language) and open the settings dialog the whole dialog is still in English (the base language).
The settings dialog's XIB file is located in the base.lproj folder and the corresponding .strings file is located in the de.lproj folder (which should be correct as the preview shows the correct translations).
I don't know what's going on and have no clue what might be the issue.
Does someone have any clue?
I'm using Xcode 6.1.1
I found the reason for this issue: Localizing the settings dialog forced Xcode to move it into the Base.lproj folder. But instead of moving the file Xcode just copied it into that folder - so the XIB file for the dialog existed twice and Cocoa used the old one (which was not localized).
After cleaning the build directory and deleting the derived data for the project the localization works fine now.
I think I'm literally on the last step before submitting a new Mac app, and I've been banging my head against a wall for the past few hours on what I think should be really, really easy.
I've designed document icons for the two different types of icons my app creates and works with. I created a new "Icon" in Images.xcassets, and dropped the appropriate files into the drop zones.
In the product editor -> Info, I go to where the document type information is, but when I try to enter in the icon name in the "icon" field of either the Document Types or Exported UTI section, the icon image just turns into a question mark—no options show up in the drop down menus for icons.
How do I get the images/icons in the asset catalog to show up in the editor? Alternatively, if I was going to enter that manually into the plist, what sort of format would I use to reference an Icon file from the asset catalog?
I know I'm probably missing an easy step here, but I can't see it!
To my knowledge, Xcode doesn't currently support using .xcassets for document icons. This is a little strange—the .xcassets editor clearly allows you to create new icons, but it doesn't generate .icns files, it just puts all the files in the same folder and uses a plist to manage them.
To create an icon for your document types, upload the 1024x1024 version of the icon to http://iconverticons.com/online/ to convert it to a .icns file. Alternatively, you could use a third-party tool to generate an .icns file with different images for different resolutions. There used to be a great tool included in the Developer Tools for doing this, but I can't seem to find it anymore.
Once you've got an icns file, add it to your project and you should be able to select it as the "Icon" for your Document Type or External/Internal UTI. Enjoy!
To be honest, it might be worth filing a bug about this. Xcode's development seems so strongly driven by iOS these days, they may not have noticed this yet!
I did it in the most easy way:
Add "New OS X Icon" to images.xcassets and name it "DocIcon", for instance.
Drag and drop images of your document icon
Just type "DocIcon" to icon name of your document
You will see question mark as document icon thumbnail. Don't care about. All will work fine after build and launch of application.
This is what worked for me, using Xcode 10 in 2019 (none of the other answers worked in my case):
Select asset catalog in Project Navigator
Right click on the left pane (list of assets) and choose App Icons & Launch Images ▶︎ New macOS Generic Icon (second option from bottom). Name it "Document". This will create a folder named "Document.iconset" in the asset catalog directory.
Populate all entries with your custom images. They must all be of the appropriate size (e.g., "16 x 16 #2x" must be 32 x 32 pixels, otherwise you will get yellow a warning icon over the image slot).
Navigate to the asset catalog folder, and use the command: iconutil -c icns Document.iconset (must match the name of the icon created in step #2). I took this command from Apple's documentation here (which by the way, also says some BS about Xcode "automatically creating an .icns file from your .iconset folder on build". Sure...).
Copy the newly created Document.icns file as a resource to your project.
Select the target, open the Info pane, and in both Document Types and Exported UTIs set your .icns file as the icon for the file type.
Hej, allesamme,
I had the same problem and have been researching it for days. I found a family of four solutions, the first three of which did not work for me: 1. using a .png file as the document type icon file; 2. using a manually created .icns file as the document type icon file; 3. the above solution, and 4. what I will describe here. Only the last one worked for me.
I tried following the spirit of the above advice and found that it didn't work, at least for my MacOS app. I'm on OS X 10.9.2 (13C64) running Xcode Version 5.1 (5B130a).
The current wisdom seems to be to create a directory in your workspace with a lower-case name and .iconset extension, in which one puts files with an icon_ prefix and the usual suffixes (16x16.png, 16x16#2x.png, 32x32.png, etc.)
In Product Editor's Info pane you can go into Document Types and associate the .iconset file with the Icon field. The icon image happily displays something reasonable. The build process builds a .icns file from that spec and copies it into your app.
I had an intermittent problem that the .icns file wouldn't build, which I traced to mistakenly haven included a 64x64 icon in the list. That's a no-no.
The current Apple dogma on this issue can be found in the official documentation, which covers some details I glossed over here. I didn't need to edit the Info.plist file directly: everything seemed to work from the interfaces provided in Xcode.
I have no idea which solutions work in which contexts, but thought I'd add throw more alternative on the fire for people to try out. — Jim Coplien
I have done everything you are supposed to do to make a custom font show up in an Xcode project. However, the font comes out Helvetica every time and not Oswald as I hoped. Here you can see the name of the font is in fact, Oswald. I also tried different names - Oswald-Light, Oswald-Regular, Oswald-Bold...
Here you can see that the .ttf files are in fact in my project. They are also in the projects folder in the finder - I checked that.
I put the names of the files in the .plist under Fonts Provided by Application.
And finally I told the label to use Oswald font. Again, I tried #"Oswald-Light",#"Oswald-Bold"...
Solution:
Make sure the ttf files are in the target's Copy Bundle Resources build phase. If they aren't, they won't get copied to the app bundle when you build the project.
Solved by Mark Szymczyk - third comment (just to make it explicit in SO-style that the problem was solved)
I have been learning a lot about writing Objective-C code and designing in Interface Builder and I wanted to set icons for my simple programs.
I added the same JPG to all the size fields in Icon Composer and got an ICNS, but I couldn't figure out how to add it to the project.
Thank you in advance.
Since Xcode 4.4 Icon Composer is no longer the recommended way to create icons and is no longer included in the standard install of Xcode.
Due to the introduction of Macs with retina display, it is now recommended to provide high resolution versions of all graphics including app icons.
To give your app an icon under Xcode > 4.4 do the following:
Create a folder [IconName].iconset in Finder
In this folder place your icon as png files. You'll need the icon in
sizes of 16px, 32px, 64px (retina only), 128px, 256px, 512px and
1024px (retina only)
These icons must be named with the pattern icon_16x16.png,
icon_32x32.png, icon_128x128.png and so on
To support retina displays you must also add icon files with double
resolution, named icon_16x16#2x.png (with size 32x32),
icon_32x32#2x.png (size 64x64) and so on up to icon_512x512#2x.png (size 1024x1024).
drag this [IconName].iconset folder to Xcode (copy if necessary)
in the info.plist file set the "CFBundleIconFile" (Icon File as Key) value to
[IconName] but without the .iconset extension
Annotations:
it is (currently) not required to provide the #2x icons
it will (usually) also work if you don't provide every icon file
the iconset folder should not contain a icon_64x64.png file. the 64px icon is only for the retina version of the icon_32x32
Update:
In the end your .iconset folder has the following 10 items:
icon_16x16.png
icon_16x16#2x.png
icon_32x32.png
icon_32x32#2x.png
icon_128x128.png
icon_128x128#2x.png
icon_256x256.png
icon_256x256#2x.png
icon_512x512.png
icon_512x512#2x.png
Official guide:
https://developer.apple.com/library/content/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Optimizing/Optimizing.html
Additional information:
To convert the iconset folder to an icns file, run the following command on the terminal:
iconutil -c icns [IconName].iconset
where [IconName] should be replaced with the prefix of the iconset folder. You now have a file called [IconName].icns. In Xcode 4.4, in the Target Summary, right click the question mark for the icon, then select the icns file. You should then see the question mark get replaced with the icon.
As of Xcode 7 (not sure when this was originally introduced), you can use the Assets.xcassets file for app icons. This file is included by default for new projects.
Simply:
Go to your target's settings and ensure that under General, App Icons the Source is set to AppIcon.
Add all 10 png icons to your Assets.xcassets's AppIcon image.
Delete derived data if you have launched the app before, otherwise it will continue to show the default icon.
Run the app; it should now show your icon in the Dock, Application Switcher, and anywhere else it should appear.
Follow these steps to add an application icon to your project. This is the icon that will be show by the MacOS in the doc bar and alt-tab display.
Create an icon .icns resource file
Place it in the "resources/macos" folder
Add it to the resources group in the xcode project
Edit the Info.plist file and change the "CFBundleIconFile" value string to "icon"
Also, img2icns tool can come handy to convert images to an icon.
It's easy
Use automatic tool (Such as IconFly) for create correct ICNS or iconset with all necessary size.
Then drag and drop created ICNS or iconset to Xcode.
in the info.plist file set the "CFBundleIconFile" value to [IconName]
Steps to add an application icon to your cocoa project.
Find 'Icon Composer' from spotlight.
Drag and drop the icon(name should be like imagename.icns) in the given boxes.
Select one box and save it.
Drag and drop the saved image in the Resources folder of your application.
Select target-->right click on project name-->Select GetInfo.
In Properties enter the name of 'Icon File'.
Now Clean Build and run your application.
Xcode 8.2.1
Convert .png 👉.icns via IconMaker
Add the AwesomeApp.icns file in the same folder as info.plist
Drag AwesomeApp.icns file into xcode in the same folder as info.plist
In info.plist set icon: to AwesomeApp.icns
Step 1: Get iconfile name from info.plist and place icns(icon file) folder in SourceCode/resources folder
Step 2: And same thing goes for xcode,you have to copy all images from xcode using copyallframeworks or copyall resource file in your xcode and build the app again.