I have an issue with an icon font not displaying on iOS 12 (it works perfectly fine on iOS <= 11). A few more details on what I've found and how we use the font:
1) The font is properly included in the project and it appears when NSlogging [UIFont familyNames] and [UIFont fontNamesForFamilyName:iconFontFamilyName]
2) I'm accessing the icons using the \u notation: label.text = #"\uXXXX". When XXXX does NOT exist in the font, the app displays the "question-mark-in-a-square", indicating (correctly) that the code does not exist. However, if the code DOES exist in the font, then the app displays nothing at all - the respective element appears blank.
Is there something we're missing here?
In summary, the issue is most likely with Icomoon's font generation; specifically the types of cmap encoding subtables. I would suggest two actions:
Test this hypothesis by using a font conversion tool (such as https://onlinefontconverter.com) to convert your ttf file to otf (which is also supported by iOS).
If your glyph displays then continue to use your new otf file while raising the issue with IcoMoon directly.
I remember having a similar issue when playing around with on-device font generation in my MinimumRubber project. I found that careful choice of platform identifier and platform-specific encoding identifier were required for both UILabel and UITextView to display the glyph. It does not surprise me that Apple has refactored this area of code
Related
I am trying to use custom font (Bebas Neue) in my iOS application. The steps I took are:
Copy the .otf files to the project.
Confirm the .otf files have set the project as target.
Added the .otf files in 'Fonts provided by application' in plist.
In Build Phases, the .otf files are in 'Copy Bundle Resources'.
Install the font on my Mac.
Try to print out all fonts available but I can't see my custom font.
The code I used:
for name in UIFont.familyNames() {
println(name)
if let nameString = name as? String
{
println(UIFont.fontNamesForFamilyName(nameString))
}
}
Trying to set the font in code and it worked.
The code I used:
textLabel?.font = UIFont(name: "BebasNeueRegular", size: 14)
But I can't set it in interface builder. Any idea?
Screenshots:
Try Below Steps: Code tested in Swift 3.
Step 1: Add Your custom font into your project( Make sure Add to Target
ticked).I am using "PermanentMarker.ttf","Pecita.otf" and "AROLY.ttf" font as a test font.
Note: Supporting font Type ttf and otf (Both font types should work)
Step 2: Modify the application-info.plist file.
Add the key "Fonts provided by application" in a new row and add "PermanentMarker.ttf" as new item in the Array "Fonts provided by application".
Your plist should looks like this
Now the font will be available in Interface Builder. To use the custom font in code we need to refer to it by name, but the name often isn’t the same as the font’s filename
Now, You can access the Custom Font from your viewController. I am testing the font by placing a UIlabel to the Storyboard like below.
Update 2: Working Solution
After, imported your custom font and updated your plist.selectlabel from your storyBoard,goto Attributes Inspectorunder Label>Text type> select to Attributed and choose your custom font from the list.
Output:
Update 1
If your custom font still not listed in Xcode font list.check the related link to your issue
http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/
custom font not displaying on some simulator
Note: Still,You can assign BebasNeue or custom font programatically to your label or button etc. even its not showing in your interface Builder.If you having trouble setting font to your object programatically.try below method.
Assign font to UILabel:
label?.font = UIFont(name: "BebasNeue", size: 35) // Set to any size
Assign font to UIButton:
button.titleLabel?.font = UIFont(name: "BebasNeue", size: 35)
Assign font to UITextField:
textField.font = UIFont(name: "BebasNeue", size: 25)
Assign font to UINavigationBar:
navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont(name: "BebasNeue", size: 25)!, NSForegroundColorAttributeName: UIColor.red]
Assign font to UIToolBar:
UIBarButtonItem.appearance().setTitleTextAttributes([NSFontAttributeName: UIFont(name: "BebasNeue", size: 25.0)!], for: UIControlState.normal)
Output:
Its Easy and simple now- Tested in Xcode 10 and swift 5
Steps to add font to your Xcode
Select your UILabel, UITextField or whatever then under fonts section and follow
Step 1
Select settings menu from left corner of font selection screen. And choose font manager option.
Step 2
Click on the add button as marked below.
Step 3
Select the folder that contains your font. It will be loaded into XCode fonts list.
Steps to add fonts to your project
Don't forget to add description to your plist with the key Fonts provided by application and put font files inside copy bundle resources under project target settings.
Yes! thats it.. njoy..
When using the same font (Bebas Neue), I experience the exact same problem: the font does not show up in the font list for Plain controls.
It does for Attributed controls, as described in Update 2 in Joes post, but then you're actually changing the attributedText instead of the regular text, which may lead to unwanted behavior. For example, you'll have to fiddle with NSMutableAttributedString to change the text or text color at runtime.
I did some investigation on this issue. I used FontLab Studio to modify the font and do some tests. I used Bebas Neue version 1.400 (dated September 15, 2014) from dafont.com.
Maybe the font file was somehow corrupted. Re-saved as .otf and .ttf: Didn't work.
Maybe the meta data of the font were corrupted. Copied all the glyphs to a new font and named that Bebas Neue: Didn't work.
I renamed the font from Bebas Neue to BN: It works! But why?
Maybe you can't use "Neue" in a font name (since Helvetica Neue was the iOS system font up to iOS 8). Renamed the font to Test Neue: Still works.
Maybe you can't use "Bebas" in a font name then? Renamed the font to Bebas: Still works.
What... Just to be sure, I changed the font name back to Bebas Neue: Doesn't work again.
I also tried BebasNeue: Also didn't work.
Then I changed the name to Bebas Neue Whatever: It works.
I really do not understand why this is happening.
Doesn't Apple or Xcode want you to use "Bebas Neue" or "BebasNeue" in the Interface Builder?
I had the normal Bebas Neue installed. Maybe the reference got corrupted?
I really can't tell. Maybe someone on a clean system can try if Bebas Neue works in their Xcode.
Anyway, I achieved my goal: being able to use Bebas Neue (I named the final version "Bebas Neue MyAppName") for Plain styled labels and buttons, so I can design my app as-is and don't have to fiddle around with attributed strings.
Finally, I found the root cause of issues with Bebas Neue fonts.
I don't remember where I have downloaded the fonts, but Bebas Neue fonts are inconsistent.
Download i.e. app called Typelight
Open not Regular, but i.e. Bold font with Typelight.
You need correct most of the Bebas Neue fonts.
maybe there is a difference between folder name and font name the solution would be:
Print all default fonts names.(without custom fonts)
Add custom fonts to project.
Print all fonts names.
and after that compare fonts names.
func printFontsNames() {
let fontFamilyNames = UIFont.familyNames
for familyName in fontFamilyNames {
print("------------------------------")
print("Font Family Name = [\(familyName)]")
let names = UIFont.fontNames(forFamilyName: familyName )
print("Font Names = [\(names)]")
}
}
You can actually just go into attributed fonts, click the custom font window. There click the gear in the upper left and click on the option manage fonts. A window should pop up and on the top and there should be a plus sign to allow you to add fonts. Just choose the custom font you downloaded like xyz.tff and then it should be added.
Important to note is that ttf file should be referenced in the p-list as well as in your project directory!
TLDR
Create a new user account in Mac OS and see if you are able to have success in the new account BEFORE going through all the steps that I went through below. In hindsight, I probably could have just performed steps 7 and 11 and saved hours of hassle.
Problem
After begrudgingly upgrading to Catalina from Mojave so that I could run the latest and not greatest version of Xcode (11.5), I was no longer able to select a custom font from the font picker for PLAIN text controls within interface builder.
As others have mentioned, attributed text works fine, because it uses the systems font picker instead of the "black box / where did these fonts come from???" picker that comes up when using plain text.
Failed Steps
I tried the following steps with no success:
Re-add the font files to the project in hopes that Xcode would fix
the link to the font table that the picker is loading from (still
have no idea why there are certain fonts in the picker and where it
is getting them from).
Reset the Mac OS font caches using several terminal commands in hopes that the picker is loading the list from a corrupt font cache in the OS
Reset the system fonts by choosing File > Restore Standard Fonts in the Font Book app
Screamed at the computer and cursed Apple for what they have become
Tried installing the fonts in the OS to see if that resolved anything, because I remembered it worked a couple years ago when I ran into something similar.
Searched the internet for any clues and tried virtually everything that seemed reasonable.
Created a brand new simple project ... still could not select a custom font ... ruh oh
Bring in the Big Guns
Cursed myself for not performing a CLEAN install of Catalina and decided to reinstall Catalina from scratch.
Realized that I made a mistake using Time Machine to backup my data before re-installing, because it would not let me bring in just my data files. The Migration Assistant requires the Library data to be imported (option was grayed out when restoring), which I did not want to do ... cursed Apple and myself again because I knew this was gonna bite me in the ... as I suspected there was garbage in the profile that was causing this (I was right ... see below)
Tried to select the font in Xcode while running under the IMPORTED account from Migration Assistant ... SAME PROBLEM ... could not select a custom font
SUCCESS!!!
Created a new user and created a new simple project under that account. BINGO!!! I could select a font now!!! Somehow my user account was corrupted during the upgrade to Catalina
It was an old bug since Xcode 3.x:
there is a bug/known issue with IB on XCode 3.x with non-standard fonts and Interface Builder. Custom fonts generally need to be set programatically (via [UIFont fontWithName:])
There are some work around like this with User Defined Runtime Attribute and categories .
I had similar problem
added custom font and also assign it to UILabel all working fine but after a few times later it's wont work as expected.
Trying all solution but nothing work for me. So here is my solution, again going to previous UILabel (already have newly added custom font) select->label->select newly added font. Check other UI controls Font.
now it's working fine.
Hope this help newDevs...
This is still a recurring issue for me with Swift 4.2, even without making any changes that would cause it.
Removing the font files from the Xcode project and adding them again fixes the problem (until next time).
In my case, a font family was missing in Interface builder, because one of the fonts from that family was not added to the project, but was indicated in the info.plist file.
Generally removing all my custom fonts from the project and adding them again - fixed the issue.
I am designing an iOS (SpriteKit) app and have found the Skia (substitute this for any unknown font) font in the list of available fonts in the font-picker if I add an SKLabelNode to the scene. However, when I run the app in the simulator a substitute font appears.
As far as I know, this font came with Xcode. I certainly didn't buy it, although it could have come as part of another application.
Using a font like Chalkduster seems to work OK and does not require an additional work.
So I am wondering if this font requires any special actions to get it to be recognised (e.g., is it like a custom font) or is there some other issue.
Furthermore, if this isn't a standard Xcode font, could I get to get in to trouble for using it in a commercial app?
EDIT: it would be appreciated if answers could state (a) whether this font is visible in their version of Xcode and (b) whether it works.
EDIT2: OK, so a bit more research. I downloaded and installed a real (free) custom font and this now appears in the font-picker, but it is not actually rendered by my app.
So it appears that Xcode shows all fonts installed on the system, whether they are accessible by your app/target device or not. However, you can only use it by following the procedures described in the answers below. This is probably a good thing as it would stop you using accidentally using a font that you have acquired and for which perhaps you don't have the licence. But is a bit annoying that fonts you can't use are offered in the font-picker.
Skia is not part of the fonts included with iOS. You can get a list of all preinstalled iOS fonts from iosfonts.com or wptechonlogy.com
You can list all installed fonts on your device by doing this:
NSArray *fontFamilies = [UIFont familyNames];
for (int i = 0; i < [fontFamilies count]; i++) {
NSString *fontFamily = [fontFamilies objectAtIndex:i];
NSArray *fontNames = [UIFont fontNamesForFamilyName:[fontFamilies objectAtIndex:i]];
NSLog (#"%#: %#", fontFamily, fontNames);
}
(source for above code)
To install a font, you can either use an app like iOS Font Maker or use code to do it yourself. The steps involved are:
Include your fonts in your Xcode project.
Make sure that they’re included in the target.
Check that your fonts are included as Resources in your bundle.
Include your iOS custom fonts in your application plist.
Use UIFont and specify the name of the font.
Codewithchris.com has a step by step tutorial on how to add a custom font.
Regarding your last question, yes. If the font is not provided as part of the iOS fonts you will have to obtain its license (some are free but some are not so make sure to be on the safe side).
Check this license page for Skia
So I am still wondering why I can see it in the Xcode font picker
Xcode is running on your computer. Once you choose Custom as the Font pop-up selection for an interface object in Interface Builder (such as a UILabel or, as you have discovered, an SKLabelNode), the Family pop-up shows all the fonts on your computer.
I have one Apple Watch app that is using Menlo Bold font for label.
In first version of Xcode that supported watchkit I was able to change font of label in storyboard to Menlo Bold 36 and everything was working fine.
In curent version (Xcode 6.2) that is not possible any more, so I found this tutorial on how to set custom font in Apple Watch, http://www.tech-recipes.com/rx/53710/how-do-i-use-custom-fonts-in-my-apple-watch-app/
I this tutorial I found this code:
func printFonts() {
let fontFamilyNames = UIFont.familyNames()
for familyName in fontFamilyNames {
println("------------------------------")
println("Font Family Name = [\(familyName)]")
let names = UIFont.fontNamesForFamilyName(familyName as String)
println("Font Names = [\(names)]")
}
}
This code print available fonts.
It is used to see why is the name of the font that you have added.
At this stage I have not added any custom font, but I run this function just to see what font are available on Apple Watch by default.
After running this I found:
/* lot of fonts before */
------------------------------
Font Family Name = [Menlo]
Font Names = [[Menlo-BoldItalic, Menlo-Regular, Menlo-Bold, Menlo-Italic]]
------------------------------
/* lot of fonts after */
It look like that my Menlo-Bold is available on Apple Watch, but I just can not select it in StoryBoard.
So , I was think this is very good, I do not need to add font I will just use it.
This is my code:
// must maee attributed text
let attributedTextForHour = NSAttributedString(
string: "IS IT WORKING",
attributes: NSDictionary(object: UIFont(name: "Menlo-Bold", size: 36)!, forKey:NSFontAttributeName))
// with atributex text
mylabel.setAttributedText(attributedTextForHour)
When I run this code in simulator, font of the label is not changed.
And here are some other strange things:
in debugger, when I set break point on mylabel.setAttributedText(attributedTextForHour) and do quick look on attributedTextForHour it is showed in correct font.
So in debugger it is fine, but on simulator it is not.
So how to fix this ?
I do not have Apple Watch, so I can see what is happening on real device.
So, I do no know is there some problem in my code or this is bug form Apple.
If somebody can test this on the is computer and report results, that will be useful also.
Maybe whole problem is because I have not added Menlo Bold font from outside and I am using what printFont() function has shown.
So if anybody know where I can download Menlo Bold font, please provide link, so that I can test that also.
I manage to solve this problem, so I am posting for future generations.
There are few things that I have learned from this (after 3h of work)
Font that are by default printed by printFonts() they look-like that are available but they are not.
you can add your *.otf font by following http://www.tech-recipes.com/rx/53710/how-do-i-use-custom-fonts-in-my-apple-watch-app/ and then you can just select it in Storybord by custom font, so you do not need to make NSAttributedString
If you want to add font that is already printed in printFonts() that things become complicated.
You can not add it by same name, so you must add it with different name, I called it Menlo-Bold-My.otf, and you must change some ID of font.
So Menlo-Bold-My.otf is same as Menlo-Bold.otf from Apple.
For converting, manipulating fonts I used program http://fontforge.github.io/en-US/
I am experimenting with the new iOS 7 SpriteKit.
This line of code is taken from apple class reference and can be found in their sample project as well.
SKLabelNode *label = [SKLabelNode labelNodeWithFontNamed:#"Chalkduster"];
In this line the Chalkduster font is used.
I understand it's a bitmap font but how do I know what other font name I can use to replace Chalkduster?
You can also view the available fonts within Xcode itself by going to your storyboard file. You create a label there, go to the label's Attributes Inspector (the slider icon in the Utilities bar), select Font -> Custom, then scroll through the Family section to view the font list.
And here is how you would use a custom font of your own. Make sure you go through steps 1-5, then you should be able to use your custom font using [SKLabelNode labelNodeWithFontNamed:#"Font Name Here"].
Here is a list of iOS 7 installed fonts
I found that there is a very useful website showing all the available fonts on iOS. It’s iosfonts.com. The website shows how given font looks like, its name and its code name as well as the iOS version when specific font was added.
You can also log all the font names that are available as described here:
How to log names of all available fonts in iOS project.
I am working with custom fonts and I have applied a custom font called "CicleSemi", I have added this font in info.plist file and below is the code which I have written
DateLabel.font = [UIFont fontWithName:#"CicleSemi" size:15.0];
This works fine, for english language in my app, but for russian language , I know that this font is not available , so Xcode automatically shifts to system font and its shifting also but the issue is that the font is becoming "BOLD" but I want it normal, and I dont have any clue what might be the issue, how xcode is treating this.
So friends, if you have any clue or suggestions please let me know.
Regards
Ranjit