How to Display different Custom arabic fonts in iPhone application? - iphone

In my application i need to display arabic text with different custom fonts. I follow the scenario adding ttf files to info.plist.
As per above scenario i am successfully getting display text in different font style for ENGLISH text only. I am doing same thing for arabic font styles but here i am not getting. Why is going like that?
Please any one can help me
Thanks in Advance.

#Kareem , I took hint from Stackoverflow itself to load the fonts but could not get it working in first go. May be following steps can help you .
Add the font files to your project.
Make their entries in info.plist file
such as
you can now implement some method that loads your font somewhere in
application delegate
like
-(UIFont*) CustomFontWithSize:(float)size{
UIFont* customFont = [UIFont fontWithName:#"FX_Masa" size:size];
if(customFont == nil)
customFont = [UIFont systemFontOfSize:size];
return customFont;
}
If you notice then the name I have passes here is "FX_MASA" and not FX_MasaRegular , this was the point where I was wrong. The name that we need to use while fetching the font is the INSTALL NAME (Double click on the font to install the font on system and the name that appears in Font Book is the install name).
Hope this helps your problem as well. In case you come across any good method, please update here.

There is a nice UILabel extension in GitHub called "Font Label": https://github.com/zynga/FontLabel
This allows to load any TTF file and then draw ZLabel objects (ZLabel is an extension of UILabel) with this custom font. It is based on CoreGraphics and I tested with many custom fonts and proved to work correctly. I don't know of course the effect with arabic fonts, but it's worth a try and a feedback from you (to us and also the github project admins) is welcome.

Related

How do I use Font Awesome as a custom font in SwiftUI?

I have followed a number of tutorials in adding a custom font to my SwiftUI package. I have take the following steps:
Add Font Awesome 5 Free Solid-900.otf to my project.
Made sure that the font is copied and added to the target
Added the font file names to the Fonts provided by application array in Info.plist
Tried to get the font name
Tried a large number of permutations and combinations for the font name.
I tried the following:
Text(Text("\u{f071} Danger Will Robinson").font(.custom("Font Awesome 5 Free Regular", size: 20))
which is supposed to give me an alert icon, but all I get is a question mark.
Is there a trick to using Font Awesome in this way?
I know there are a few packages available, but I’m trying to learn more about the process itself, and I can’t see that it should be too hard.
OK, I worked it out.
For MacOS, the Info.plist key is: Application fonts resource path, not as above.
The next trick is to get the font name.
One method is to install the font, and then check FontBook. The PostScript name is the name I need.
The other is to run the following code:
let fontManager = NSFontManager.shared
let fonts = fontManager.availableFonts
for name in fonts {
print(name)
}
That’s what happens when all the tutorials are for iOS, not MacOS.

Font not loading in XCode

Well, I want to import a new Font to my application but without success. I have the Fonts provided by application key in my .plist , I have my font in the Item 0 as a String and the value AdelleBasic_Bold.otf, I have added that Font to my project, and I am trying to use it with:
_myTextField.font = [UIFont fontWithName:#"Adelle Basic" size:15];
Adelle Basic is the header of the Font when I open it. I have also tried without any success:
_myTextField.font = [UIFont fontWithName:#"AdelleBasic_Bold" size:15];
Any suggestion?
This may well not true for all fonts, but in my experience, Xcode can be fussy, & I've never been able to get it to use otf fonts (anyone who has please post!), so I've always converted my fonts using this really excellent website - Online Font Converter
I convert them to ttf fonts, and they always seem to work fine - make sure you use the exact name (changing the filename of the font seems to stop it working too).
Hope this helps.
Below is the proper way to add fonts to your XCODE app (.otf fonts work fine):
Include your fonts in your XCode project
Make sure that they’re included in the target
Double check that your fonts are included as Resources in your bundle
Include your iOS custom fonts in your application plist
Find the name of the font
Credits and better explaination with images here
you can use only the third party fonts which have extension as ttf and the fonts which have otf extension will not work effectively and mostly doesn't work
Apart from assuring the 5 points, you could also try out the following snippet of code that prints out the installed fonts:
for (NSString* family in [UIFont familyNames])
{
NSLog(#"%#", family)
for (NSString* name in [UIFont fontNamesForFamilyName: family])
{
NSLog(#" %#", name);
}
}
If the font that you want to use is not listed, then you missed in some of the 5 steps.
I just add font into project, check if font will copy inside bundle. Set up it on my Mac and directly use font inside Interface Builder. If you will have any problems solve they here.
I've seen some comments about tff and otf and I wouldn't agree, it could be that you are not using the correct font name, this doesn't mean the file name
to find the fonts you have installed in xcode run the
for family: String in UIFont.familyNames{
print(family)
for names: String in UIFont.fontNames(forFamilyName: family){
print("== \(names)")
}
}

Custom font in iphone not being displayed properly

I installed a custom font called "modern no. 20" (already installed in my mac) into my iphone project .
I copied the modernno20.ttf into my resources.
Now in my app-info.plist i added this font name in "Fonts provided by application".
Then i added
cell.textLabel.font=[UIFont fontWithName:#"modernno20.ttf" size:14.0];
in my tableviewcode .
i dont know why but this font is not properly displayed.is there any thing i missed?
In order to call the font in your fontWithName call, the string should be the name of the font as it is displayed in the Mac's 'Font Book' app, and not the actual filename of the referenced font file.
There hasn’t been an easy way to add custom fonts to your iPhone applications. As of iOS 4 it has become very easy to do. there could be possibility you would have missed some of the step to get custom font work.
Here is what you need to do in order to add custom fonts,
Check How to include ttf fonts to iOS app

Custom font doesn't work in interface builder!

I've downloaded a font that's called "aldo the apache (.tff) " from dafont.com.
I used it with different programms like adobe illustrator and it seemed to work just fine.
Recently i tried to use it in a game that i'm making to experement. It didn't work -_-.
IB was displaying the font as a slightly bigger version of arial.
How can i solve this problem and get the font to display correctly?
If you have any suggestions, please post them down below.
-DD
You have to edit your <appname>-Info.plist file and create a new UIAppFonts key with type array, where each element is a String with the name of your font file, in this case AldotheApache.ttf. Then use the name in IB or with UIFont as it shows in the application Font Book app of your Mac, in your case Aldo the Apache. Obviously the font should also be added as a resource of your project.

Best way to display barcodes from NSString

Just wondering what is the best way to display a barcode given a string on the iPhone. I have looked over stackoverflow and google and a few people have different ways each requiring a decent amount of work (I think) and also slightly old so I wanted to get it right first time.
One way I've read is using a custom font that you can now use in iOS4, using this font Someone else has written a class to import custom fonts, though this apparently isn't needed for iPads.
I have also found a Library but not much further details on it.
If using the font is the best way is the font linked above good or are there better ones?
Cheers for any help.
Well I went ahead and checked it out anyway. Fonts work extremely well and are very easy to implement. Basically copy this barcode font into your project. Then in your App info.plist type this in:
<key>UIAppFonts</key>
<array>
<string>3OF9_NEW.TTF</string>
</array>
For the above linked font.
Then in where you want to place the barcode just use a UILabel and then for the font use :
label.font = [UIFont fontWithName:#"3 of 9 Barcode" size:40];
Note that the font name is not 30F9_NEW.TTF. If you are using another barcode font or other font in general just open the ttf file in font book and it will say the name up the top of the window. Also you need to have a * at the beginning and end of the string you are using. If you navigated here looking at how to implement a custom font you can do it the same way, just not the font name isn't the file name.