How to get the System font in an iOS app? - ios

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

Related

UIFontDescriptor can't find iOS font

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

Custom fonts FMX ios not working Delphi 11

With this Embarcadero tutorial on custom fonts we were enabled to use custom fonts on iOS and Android:
https://docwiki.embarcadero.com/RADStudio/Rio/en/Creating_an_iOS_App#Using_Custom_Fonts_in_iOS_Apps
With new projects we cannot get it to work anymore in iOS, since Delphi 11 (or maybe 10.4). It’s only working on Android.
Does anyone know why the fonts are not picked up/ embedded on iOS?
I have created a sample application showcasing the use of a custom font on an iOS application. Please, the code is available here. It is important to bring up here the need to add the custom font file to the project deployment list:
The mentioned sample application contains a combo box to list all the font family names that are available as value for the TFont.Family property. I have added the SCRIPTBL.ttf font file to the application and it causes the Script MT Bold item to be added to the mentioned combo box.

iOS font freetype trueType AAT

Last day, I see many thing about iOS text. Now I want to know, what is the real fontType apple use. someOne say iOS use freeType, but I print all of the image, not fount libFreeType. other one say iOS use ATT CGFont, but this is not say very clearly. I don't find any lib for this. what is the real Font engine for iOS.
Thank you.
Here Apple Doc ..Please Refer this
Apple currently provides support for drawing using AAT fonts via Apple
Type Services for Unicode
https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6AATIntro.html
For The Font Engine https://developer.apple.com/fonts/TrueType-Reference-Manual/RM02/Chap2.html

Handling Cusom Key Board Types in ios [duplicate]

This question already has answers here:
How to add custom fonts to an iPhone app?
(2 answers)
Closed 8 years ago.
Here in (http://iosfonts.com/) this site, number of fonts are listed that iOS devices supports. For an Indian language, Tamil, there is a font named Sangam. My understanding is that there is no Localization support for the languages Tamil, Telugu or Devanagiri. As iOS supports TTF and OpenType fonts both to be added to the XCode, Is it possible to create a custom keyboard lay out, for typing using these fonts. As these languages has no similarities with any of the language keyboard that apple supports presently, is there a way to type, store and share the text contents using these custom type fonts.
Yes, simply embed the font files (.ttf or .otf files) in your app then add them to the list of the dedicated UIAppFonts key in your Info.plist file (Note: the key is called "Fonts provided by application" in its human-readable description).
See the doc here.
You can then simply use [UIFont fontWithName:size:] with the name of your custom font to manipulate the font and affect it to your labels and so on.

Dynamic Type on iOS7 backwards compatible with iOS6

I am trying to setup Dynamic Type in my app that should be compatible with 6.1+.
I am using preferredFontForTextStyle: and it obviously crashes on iOS <7.0
How are you addressing this?
respondsToSelector: and splitting in two every font setting?
Is there a better way?
Thanks in advance!
You can patch UIFont dynamically only if iOS version is lower than 7.
What should you do to patch unexisting method:
Prepare your own replacement of unexisting method.
Check the OS version - 'respondsToSelector:` is a great way to test it.
Add an implementation if method doesn't exist.
In UI7Kit, I patched it using addClassMethodForSelector:... which is provided by FoundationExtension.
See: https://github.com/youknowone/UI7Kit/commit/701c44a69406ad971794c9ab46aeb0cfac1fa207#L3R57
This code add new method preferredFontForTextStyle: from existing method implementation __preferredFontForTextStyle:
Additionally, UI7Kit starts to support the method right now. (in very rough way yet)
Try it if you want.
I've been thinking about this; probably the best way to do it would be to manually add the preferredFontForTextStyle: method onto the UIFont class at runtime if the app is running on iOS 6, and then dynamically pick an appropriate system font size there. The UI7Kit project on github does something like this for other methods, but not this one unfortunately.

Resources