Use custom font for rupee - android-fonts

I want to use custom font for rupee as Indian currency. I do not know how to use custom font. So please suggest me.
Can I directly use it in XML file?

Just try this as:
Create a folder in assets folder as named as "fonts".
Then use this code as :
Typeface fontName = Typeface.createFromAsset(getAssets(), "fonts/font.TTF");
textView.setTypeface(fontName);
Hope it will work for you. As it works for me fine.

Related

How to use R.swift for string and colors

So I have a simple question.I searched a lot and there was no such a clear answer to my question.
How can I use R.swfit for Colors and Localized String ?
R.swift completely recognize my images and fonts but how can I use them for my Colors and Localized.
I have so many colors and Localized String in my Project but R.string and R.color are empty at all
I found the answer.I was wrong about working of R.swift.for using Colors you have to define them in Assets.xcassets as a new color set.after creating colors there you can use them via R.color.
For using R.string you have to create a new File.string file in your project and define your strings in a key-value format like "variable" = "something";. After that, you can use R.string.File.variable() to use those strings.

Roboto Font not working in Xamarin iOS

I tried to use custom font in Xamarin iOS using this guide. I added the fonts to Resources/Fonts folder. And then added it to the info.plist under the array property Fonts provided by application. I changed the property of font to Bundle Resource and Copy Always.
Now, the newly added font have to be shown in xamarin designer. But, it is not showing for Roboto-Regular.ttf. But It is working fine for OpenSans-Regular.ttf.
Any help are welcome!
iOS may register the font under different font name. If your font was successfully registered (as your steps indicate you did), you can find it inside UIFonts.FontFamilyNames array and then use that. To find all registered fonts,
foreach (var fontFamily in UIFont.FamilyNames)
{
foreach (var font in UIFont.FontNamesForFamilyName(font))
{
System.Diagnostics.Debug.Console.WriteLine(item);
}
System.Diagnostics.Debug.Console.WriteLine("---");
}
if you still don't see your font. Try to find it explicitly by name,
foreach (var font in UIFont.FontNamesForFamilyName(friendlyFontName)) // can have space in font name.
{
System.Diagnostics.Debug.Console.WriteLine(item);
}
System.Diagnostics.Debug.Console.WriteLine("---");
If you find your font there, that's what you need to use as font name in your code.
Example,
I recently used Bbas Neue. The file names where,
BebasNeue Regular.ttf
BebasNeue Bold.ttf
BebasNeue Thin.ttf
In android, I used BebasNeue Regular.ttf#BebasNeue Regular and it worked as expected. In iOS, however, the font names were as follows,
BebasNeueRegular
BebasNeueBold
BebasNeue-Thin
as you can see, not in any pattern. So after looking for font family Bebas Neue (with the space), I found the correct names, and was able to use the font on iOS.
Hope this helps.

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)!])

Embedding ttf fonts doesn't work perfectly Obj C

I'm trying to embed the Open Sans font family (ttf files) into Obj c. I've added them to my info.plist and I'm able to use some of the fonts, but (for instance) the OpenSans-CondLight.ttf font doesn't show up when I check all the fonts embedded. Anyone got a possible explanation for this? There is nothing wrong with the ttf files.
Yes. Likely the name of the font file is different than the font name itself. I would look for the font name. You can get this by going to the TFF -> Right Clicking -> Get Info -> "Full Name" (See: How do I get the font name from an otf or ttf file?).

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

Resources