Adding a Custom Font (Lexia) - ios

i am trying to add Font Lexia into my project but its not working. what i did was;
i downloaded .ttf files from here: http://www.dafont.com/lexia.font
dragged two LEXIA___.ttf and LEXIB___.tff files into the project and added them to the target as well (i even tried copying them into Bundle Resources)
then i added them in plist file but of no use. (i tried using different names but didnt work)
i tried to get names in the code but its not appearing there
NSArray *arrFonts = [UIFont familyNames];
NSLog(#"name = %#",arrFonts);

The ttf files need to be added to the Resources section of your project. Then the names you put in the Info.plist file (your Marsden-Info.plist) needs to match the filenames of the ttf files.
You entered Lexia-Regular.ttf and Lexia-Bold.ttf but the files appear to be named LEXIA___.ttf and LEXIB___.ttf. The names must match exactly, including case.

Related

NSLocalizedString is returning the key

In my framework app, I have some localization files added and have a method to get
localised strings as follow
-(NSString *)getCurrentLocale{
return NSLocalizedString(#"mykey", nil);
}
and I have installed this pod into one demo app, and trying to get the locale but it always returns the key, (it returns 'mykey')
I have double checked the format and name (Localizable.strings) within the string files
all files has proper format
but I do have locale strings as values in my Localizable.strings
ex: "mykey" = "ar_SA";
any Idea where I am going wrong?
Usually, this happens when you don't have the Localizable.strings file in the appropriate language folder (e.g. de.lproj). Also, ensure you haven't put your Localizable.strings file in the Base.lproj folder, as the same problem will occur.
To summarize, make sure your project Localizations have their Localizable.strings files in their respective language folders to provide the correct translations.
Finally, if the above are true (and this may be obvious), the device must have its locale set to actually pull strings from a given language.
Reference: Internationalization and Localization Guide

Custom Fonts only available when set in Interface Builder

I have added a custom font to my project.
It is included in the target, and it is added in the plist.
When I try to use it programmatically it doesn't work, and it doesn't show up when I print out a list of available fonts.
However, it does show up as an option in Interface Builder, and if I set a label's text to that font in IB, it works correctly and shows up when I print out a list of available fonts.
This is XCode 6.4 and iOS 8.0
When it is working via IB, it gets printed out in the font names like this:
Special Elite
SpecialElite-Regular
I call the font programmatically like:
[UIFont fontWithName:#"SpecialElite-Regular" size:fontSize];
There are no problems when doing this with the built-in fonts.
When I try to use it programmatically it doesn't work, and it doesn't show up when I print out a list of available fonts
This proves that you have not in fact included it properly in the target and the Info.plist.
The reason it seems to work in IB is that this font is also present on your computer. But in fact if you were to run this app on your device, you would see that even setting the font in IB is not working.
Your font is Special Elite. As you can see, I have it visible here in my running app:
Here's the code that I used:
let lab = UILabel()
lab.text = "This is a test"
lab.font = UIFont(name:"SpecialElite-Regular", size:18)
lab.sizeToFit()
lab.frame.origin = CGPointMake(100,100)
self.view.addSubview(lab)
So you see, it is possible to refer to this font in code — if it is loaded properly. You are evidently not loading it properly. It's not in your app bundle, or it's not in the copy build phase, or it's not correctly listed in your Info.plist.
(Of course there's always a possibility that you're calling [UIFont fontWithName:size:] with a bad value for the name or for the size.)
Ok, topic is old but I would like to put in my two cents here.
First off all, read this article http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/
In brief:
remember to include your fonts to project
setup target for fonts
check if your fonts are included as resources in bundle
add custom fonts to plist file
check the real name of your font in code
When I did everything like described in this article, my fonts works in interface builder only. I also have problem with step 5 - my fonts did not show up in console output.
Ok, so now is time for tips from me:
TIP #1
use otf font format, if you have different, convert it (or ask your designer ;) )
you can use this site for that: https://onlinefontconverter.com/
TIP #2
In article above you can find:
Open it and add a new row called “Fonts provided by application” which
will be an array that you need to add all the filenames of the fonts
you want to use.
Instead of "Fonts provided by application" enter "UIAppFonts"
Remember, if you have more than one plist file, set this for all.
As mentioned by others, following article is very useful to diagnose the problem.
http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/
Also while adding custom fonts to Xcode project, add individual font and not the directory in which all fonts are stored. If you add that directory, fonts will be visible in Interface Builder but not in the running app.
Matt did a great job of isolating the problem... I was not loading the font correctly.
In my case the problem was in the Info.plist.
I was listing the font in the Info.plist using its name. This is incorrect. You are supposed to list the font in the Info.plist using its file name.
I know this is old but I just ran into the same issue. The font would show up only if I selected that font in the interface builder. Turns out when I searched for UIAppFonts, it didn't list the main Info.plist (we were already using custom fonts) for some reason. So I ended up adding the fonts to the localized (?) plist file which resulted in this issue. What I had to do was to go to the Project Settings > Target > Info tab and add the font file names there.
Issue is You are not giving ProperName Of Fonts in Code, for Getting Name of Fonts please run this code.
for family: String in UIFont.familyNames
{
print("\(family)")
for names: String in UIFont.fontNames(forFamilyName: family)
{
print("== \(names)")
}
}
it will prints all fonts, search your font and give proper name.
let attributedText = NSMutableAttributedString(string: "We
Apologize! \n This feature is only available for \n Go 4.0
Subscriptions", attributes: [NSAttributedStringKey.font :
UIFont(name: "SpecialElite-Regular", size: 22)!])

How to "merge" two fontello font files?

I'm making changes to an existing project that uses fontello.
And I would like to add some icons to the project's font file.
What is the easiest way to to add those new icons? Can I create a 2nd font file in fontello and then somehow merge the two font files?
When you download a Fontello pack it includes a config.json file, which is a mapping of the characters included in your custom font. If you want to add more characters to your font, you should start by uploading this config file to fontello.com, change your selected characters and then download a new pack, making sure to replace all the fonts and css files (so that the new characters start working) and this config file (for next time you want to change the set of characters included).
You can merge fontello collections using a text editor by opening the config.json file of one collection and copying the glyphs to the config.json file of the other collection. After you do that, drag (upload) the new merged config.json file to fontello.com and you can then download your new merged collection.
To add new icons, simply drag (upload) the SVG images to fontello.com. In this case you may need fix the paths (fontello will only accept files with a single path) within your SVG files before uploading them. You can do this a free tool called Inkscape by following these steps:
Open file
Select all
Object -> Ungroup
Path -> Union
Path -> Combine
File -> Vacuum Defs
Save as -> Plain SVG
If the SVG file has multiple paths that you cannot remove by combining paths, you can use Edit > XMP Editor to remove them. You should only have one path when you are done.
You can also check the svg file output in a text editor. If saved correctly, you should see a single element and an empty element.
just drag and drop your svg font to fontello home page. your previous font will be displayed. you can add additional fonts to them and download new font files.

iOS ttf fonts only partially work

I need OpenSans in my app and so I imported the whole OpenSans bunch which includes Bold, ExtraBold, Italic, Regular, Light and more. I added them to Fontbook (to check the exact name I need to address them by when using them) on my Mac, to my project in the file structure and added them in Build phases to my project as well.
Now the weird thing; when I use them with UIFont, ONLY OpenSans-Bold works. The rest doesn't work. If I use OpenSans-Bold (exactly the identifier given by Fontbook), everything works fine. If I, however, change it to OpenSans-Regular or OpenSans-Light or something else in that family, I get the systemfont with UIFont and I get nothing when drawing with Quartz.
All fonts are in all lists and I checked all the identifiers from Fontbook (which was why I couldn't get OpenSans-Bold working), but now i'm at a loss. Any idea what I could be doing wrong?
OpenSans Regular is just OpenSans, semi-bold is OpenSans-Semibold, etc.
In Font Book.app select the font and choose Command + I which brings up the font info. In the "PostScript name" in the top you can see what the font is called and how you can call it in your code.
Also, just make sure the font has actually been added in your bundle and your plist :)
You Can check the fonts provided by the ttf file With the following lines of code..
this method is provided by the UIFont class.
(NSArray *)fontNamesForFamilyName:(NSString *)familyName
You need to add the files in the right locations, then in the plist file, then enumerate them all and print them to get the PDF names so you can access them. Most likely you're using the wrong names.
Fonts have three kinds of names:
The file name
The font name in Font Book
The PDF name - this is the one you use to access the font in code
See this answer:
Adding custom fonts to iOS app finding their real names

Localizing strings from the Settings.bundle using InAppSettingsKit

I am attempting to use InAppSettingsKit to manage my settings. This uses the Settings.bundle with a .plist file and the .strings files for each of the languages being translated.
I can confirm that the translation of my strings is working properly outside of my application, using the Setting application. But when I am in my application, the translation is not occurring.
I think it comes down to code like this, from the InAppSettingsKit class IASKSettingsReader, with a couple logging statements that I thought my be helpful:
- (NSString*)titleForStringId:(NSString*)stringId {
NSLog(#"%#",[_bundle localizedStringForKey:stringId value:stringId table:self.localizationTable]);
NSLog(#"%#",[_bundle localizedInfoDictionary]);
return [_bundle localizedStringForKey:stringId value:stringId table:self.localizationTable];
}
If I understand correctly, this should be using a table with the name self.localizationTable as the source of the translation. This value is simply "Root". It's not a path to the Root.strings file in the selected language, so I am guessing that the method localizedStringForKey:value:table: must be using some global system reference that points to the correct path.
I have confirmed that the strings file name is "Root.strings" all around, with a capital R, including in the Root.plist file.
[_bundle localizedInfoDictionary] returns (null); It is doing this for two language settings of English and French.
I'm not sure how to debug this. Thanks for any help you can give.
I'm using InAppSettingsKit with localized text with no problems. Two things I can think of that you could check: are your Root.strings files located in the correct subdirectories of Settings.bundle (en.lproj and fr.lproj for English and French?
Is there a "Strings Filename" entry in your Root.plist? It should simply contain a string with value "Root"
It has been quite some time since I resolved this, and at the time, I didn't fully understand it. But, in the interest of closing out this question, I'll point to the following documentation for future reference:
NSBundle Class Reference
which refers to the following:
Resource Programming Guide
In the second document, refer to the section "String REsources -> Loading String Resources Into Your Code"
The solution contains a properly configured Root.strings file, which shows up in the file list like this:

Resources