I am trying to use Avenir Next on a NSAttributedString w/ UIFontDescriptor. It is an in-built iOS font. It works in my SwiftUI components but if I try to create a custom UIFontDescriptor it doesn't find the font and defaults to SFUI. Why is this and how can I fix it?
// descriptor shows font as SFUI
let boldDescriptor = UIFontDescriptor(fontAttributes: [
UIFontDescriptor.AttributeName.family: "Avenir Next",
UIFontDescriptor.AttributeName.traits: [
UIFontDescriptor.TraitKey.weight: UIFont.Weight.bold
]
])
I'm not sure, How you are using this descriptor method.
Avenir Next is an in-built iOS font, but it may not be available on all devices. Make sure the font is installed on the device you are testing on.
Check font is available by using the UIFont.fontNames(forFamilyName: "Avenir Next") method to get a list of available font names for the Avenir Next family.
var fonts: String = UIFont.fontNames(forFamilyName: "Avenir Next")
print(fonts) // ["AvenirNext-Regular", "AvenirNext-Italic", "AvenirNext-UltraLight", "AvenirNext-UltraLightItalic", "AvenirNext-Medium", "AvenirNext-MediumItalic", "AvenirNext-DemiBold", "AvenirNext-DemiBoldItalic", "AvenirNext-Bold", "AvenirNext-BoldItalic", "AvenirNext-Heavy", "AvenirNext-HeavyItalic"]
I also created a new project for boldDescriptor method & it is working fine in my case.
Use this project Demo Project for UIFontDescriptor -
GitHub & let me know if this example doesn't work for you.
Output:
Output Screenshot
Also, you can import font from the system into the project.
Please also check the following reasons:
Make sure your System is up to date because many of the Catalina users suffered from this issue.
Make sure you're using iOS 13 or greater version for testing the fonts. Note on official website
Make sure the required font is available in the Font Book. Search by Font Book or Search by folder.
It is unlikely that fonts would just "stop working" on their own. More likely, there is an issue with the operating system upgrade, or the font databases and caches have been damaged during the upgrade process. It is also important to only have one font manager installed on your Mac at a time, as using multiple font managers can lead to conflicts and damage to the underlying font databases and caches. If you are experiencing issues with fonts not working properly, you may need to try repairing or rebuilding the font databases and caches.
You should be able to resolve any duplicate fonts if available in your system and ensure that only the necessary fonts are installed and active. Resolve Duplicates
Related
I am wanting to use Helvetica Neue Ultra Light in my Watchkit app. I have followed all of the instructions for adding a custom font (added to Extension bundle and added in Info.plist for Extension and Watchkit app), but NOTHING is working and it will never get used.
Really strange thing is, other ttf fonts that I have added DO work, it seems to just be some strange issue with Helvetica.
Where is Helvetica, and why can't I add it?
Edit: To clear things up and prevent what people think might be obvious answers.
Watchkit only includes the system font (San Francisco), it doesn't
expose all of the fonts that iOS has. (Ref:
devforums.apple.com/message/1096179#1096179) THIS is why I am trying
to include Helvetica.
Option 1
I had the same issue. I fixed it by including the - character between the font name and the name of its weight. In some ways, Xcode could recognize the font.
Try changing HelveticaNeueUltraLight.ttf into HelveticaNeue-UltraLight.ttf wherever possible (info.plist file and in the project folder).
Option 2
Open up the FontBook that comes included within your Mac. Install the font if you haven't already and look closely at the PostScript name of the font. If it differs from the name you are currently using in Xcode, then change it.
Option 3
If you can't still get this working, download the same font from another source.
This is a topic that looks like many others have struggled with. I'm trying to add the 'Impact' font to my iOS project. To do so, I perform the following steps:
1. Add the Impact.ttf file to my project.
2. Ensure that the Impact.ttf file is in fact added to the project Target.
3. Check 'Copy Bundle with Resources' in the target Build Phases and make sure the Impact.ttf file is included .
4. In My-Project-Name-Info.plist, I added the "Fonts provided by application" option and set Impact.ttf as item 0 in the array.
5. Open the font file with Font Book and make sure I'm referencing the font by the correct name. In this case, Impact is the correct name.
I used the following code snipped to see all available fonts in the project, and 'Impact' is not one of them:
for (NSString *family in [UIFont familyNames]) {
NSLog(#"%#", family);
for (NSString *name in [UIFont fontNamesForFamilyName:family]) {
NSLog(#" %#", name);
}
}
When inspecting the value of UIFont in the following snippet, I get nil.
UIFont *impactFont = [UIFont fontWithName:#"Impact" size:36.0f];
I've quadruple checked all spellings and gone through each step multiple times. I've also used the following resources (and many more) to troubleshoot the problem.
Custom font in iOS not working
iOS custom font robot bold not working
Common mistakes with adding custom fonts to your iOS app
One item to note: If I open Impact.ttf with font book, it says that the font is not installed. I click to install the font, and get a warning that there are duplicate Impact fonts installed. To fix this warning, I click 'Resolve duplicates automatically' and the font shows as installed. However, if I open the file again, the font shows as not installed. I'm not sure if having the font installed in Font Book is necessary for it to correctly be recognized in my project .
Thank you very much for your help! I know this question has been asked multiple times, but I feel like I've exhausted all resources and links here on SO and other sites.
Maybe this is not the answer you want, but is a solution you could use to move on.
That is what i use on my projects, simple and useful https://github.com/deni2s/IBCustomFonts
Hope you can find a better solution!
I am making an app that writes/plays byzantine music and I 'd like to port it to iOS.
For that I 've been using a family of fonts that work well under windows, and also FontCreator does not show a problem with them.
However, under iOS, they do load ok with UIFont* but they are not usable, that is, when I type the character '1', the '1' in system font is displayed instead of that font.
What could be wrong?
For reference, I 've attached the font: http://www.michaelchourdakis.com/temp/ez.ttf .
Note that the font isn't loaded in the Font Book as well. So there must be a problem in the font.
There seems to be something wrong with your font. If you try install it on Mac OS (Mavericks), it shows following errors:
EZ Psaltica
'name' table usability
'sfnt' required tables
'name' table structure
I guess iOS has the same problem when using this font.
Where did you get that font from? Do you know who created it? If yes, maybe these errors mean something to him and he can fix the font? Once you get to install it correctly on Mac OS, chances are higher that it will also work on iOS, I guess.
I am using Xamarin Studio to develop an iOS iPad app. I need to assign the System font name to a variable in the code behind on one of the pages.
How do I get whatever the System font is programmatically?
NOTE: Before somebody thinks he has to change this answer: This is answering a question about Xamarin.iOS and not ObjectiveC. The API really uses uppercase properties and method names.
Create a system UIFont and read its properties:
var font = UIFont.SystemFontOfSize(10);
string familyName = font.FamilyName;
string fontName = font.Name;
See also Apple's reference for UIFont.
Starting with iOS7, you have a richer way of getting the font, using the new UIFont properties.
For details see:
http://tirania.org/monomac/archive/2013/Sep-25.html
There are some font files in my code repo for the font Nubian and Nubian-Alt. They are licensed and paid for and they need to be used. However I cannot use this font in iOS, and I cannot open the font with Font Book even though the font previews OK in Finder and is identified as a Truetype Font.
I started by trying to add Nubian-Medium to the iOS app - using the key "Fonts provided by application" in the app's Info.plist. The font did not appear in the list generated using:
for (NSString *familyName in [UIFont familyNames]) {
for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
NSLog(#"%#", fontName);
}
}
I checked the Target's "Copy Bundle Resources" Build Phase, saw the font had been added to the list.
I tried adding another font I have used in another app, "chess-merida-unicode.ttf", to check I was adding a font correctly - I copied it to the app and added it to the array of fonts provided by application, saw it appear in the "Copy Bundle Resources" list, it was reported as available using the above code snippet.
Next I took a look at the font in OS X - double-clicking does open Font Book but the font is not opened or added. When I tried to drag all the Nubian fonts into Font Book as a new collection it reported problems with all the files, specifically in tables contained within the font file.
Selecting all fonts and then choosing proceed did nothing.
I downloaded a trial of a third-party app named Font Agent Pro and it also could not load these fonts.
I found a sketchy site called fonts.com and downloaded another Nubian-Medium ("ufonts.com_nubian-medium_1_.ttf") - Xcode was able to recognise that file.
I checked the permissions on these files and made sure they were rw for all, no change.
At this point you would suspect the files are just broken or corrupted but they are in use on a web page (that is also part of the project) and that works fine. What other steps could I take? What can I do to get these files added to the iOS project? If there are certain kinds of TTF that cannot be used in an iOS project, how can I check whether these are that kind?
Step 1: Download Nubian Font From : http://www.fontpalace.com/font-download/Nubian-Thin/
Step 2: Add Font .ttf File in your project
Step 3: Register your Font With Application, set Fonts provided by application key in your info.plist file, See the ScreenShot for details.
Step 4: Create a Label and Assign the font to it ,as following
UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 50)];
[lbl setText:#"I am Nubian-Thin"];
[lbl setFont:[UIFont fontWithName:#"Nubian-Thin" size:26.0f]];
[self.view addSubview:lbl];
The answer seems to be that these fonts were "web" fonts. I don't know how to tell the difference, given a TTF file that looks just like a "desktop" font. Learning how to do this was kind of the aim of the question.
Practically speaking, digging out an old archive from someone's hard drive discovered another archive with TTF fonts that worked. These fonts still had 8.3 filenames and were all created as members of their own font family (so Nubian-Medium and Nubian-MediumItalic were in no way related). I renamed them, then ran them through the trial of RoboFonts to correct the family relationship. This resulted in TTFs all in the Nubian family. And then found a weird issue where a UILabel created with this font came with a 1-pixel horizontal rule at the top of the frame. Going through the process again but choosing to generate OTF output got rid of the line.
Fonts are easy, except when they aren't, then they are really hard.