ios apps can download the following fonts if necessary - ios

In the iOS 7 font list located here, http://support.apple.com/kb/HT5878, there is a section at the bottom with the heading "apps can download the following fonts if necessary".
What does this mean?
How does one include these fonts, and how is this different than including custom fonts?

This is interesting, it's an almost undocumented feature, but it seems ok to use and won't get your app rejected. Just trying to research this myself brought me to this question and not much else. All I could find that was documented is sample code showing how to use it: DownloadFont.
Demonstrates how to download fonts on demand on iOS 6 and later.
On iOS 6, we have added the capability for applications to download fonts on demand. Besides the fonts installed with iOS 6, applications can install a list of additional fonts as necessary.
The fonts listed are already licensed by Apple for use in iOS, however they aren't bundled with the standard iOS firmware due to the extra disk space usage. I would assume that this will continue to be how Apple provides new fonts (unless a part of the OS's UI uses it). Additionally, unlike adding fonts using the UIAppFonts key in your Info.plist, after the font is downloaded, it is available for all apps to use.

Here's a simple example on how to asynchronously download a font and set it to a UITextView.
- (void)asynchronouslySetFontName:(NSString *)fontName toTextView:(UITextView *)textView {
CGFloat size = 24.0f;
UIFont *font = [UIFont fontWithName:fontName size:size];
if (font && ([font.fontName compare:fontName] == NSOrderedSame || [font.familyName compare:fontName] == NSOrderedSame)) {
textView.font = font;
return;
}
NSMutableDictionary *attrs = [NSMutableDictionary dictionaryWithObject:fontName forKey:kCTFontNameAttribute];
CTFontDescriptorRef desc = CTFontDescriptorCreateWithAttributes((__bridge CFDictionaryRef)attrs);
NSMutableArray *descs = [NSMutableArray array];
[descs addObject:(__bridge id)desc];
CFRelease(desc);
__weak UITextView *weakTextView = textView;
CTFontDescriptorMatchFontDescriptorsWithProgressHandler((__bridge CFArrayRef)descs, NULL, ^(CTFontDescriptorMatchingState state, CFDictionaryRef progressParameter) {
if (state == kCTFontDescriptorMatchingDidFinish) {
dispatch_async(dispatch_get_main_queue(), ^{
weakTextView.font = [UIFont fontWithName:fontName size:size];
});
}
return YES;
});
}
And here's a list of all the downloadable fonts. http://iosfontlist.com

Related

on demand resources for fonts in Xamarin Forms

Can we fetch font file .otf and .ttf files on demand in Xamarin ios? Below is the sample code to fetch the fonts in swift asynchronously. I'm looking for the same in C#.
{
(void)asynchronouslySetFontName:(NSString *)fontName toTextView:(UITextView *)textView {
CGFloat size = 24.0f;
UIFont *font = [UIFont fontWithName:fontName size:size];
if (font && ([font.fontName compare:fontName] == NSOrderedSame || [font.familyName compare:fontName] == NSOrderedSame)) {
textView.font = font;
return;
}
NSMutableDictionary *attrs = [NSMutableDictionary dictionaryWithObject:fontName forKey:kCTFontNameAttribute];
CTFontDescriptorRef desc = CTFontDescriptorCreateWithAttributes((__bridge CFDictionaryRef)attrs);
NSMutableArray *descs = [NSMutableArray array];
[descs addObject:(__bridge id)desc];
CFRelease(desc);
__weak UITextView *weakTextView = textView;
CTFontDescriptorMatchFontDescriptorsWithProgressHandler((__bridge CFArrayRef)descs, NULL, ^(CTFontDescriptorMatchingState state, CFDictionaryRef progressParameter) {
if (state == kCTFontDescriptorMatchingDidFinish) {
dispatch_async(dispatch_get_main_queue(), ^{
weakTextView.font = [UIFont fontWithName:fontName size:size];
});
}
return YES;
});
}
}
I'm struggling to convert same code to Xamarin iOS c#? Is this feature compatible with Xamarin?
If you want to reduce the size of the application, you could try download fonts and install them at runtime. There is a similar issue on Github issue which you could refer to:
load fonts from web on demand. The accepted answer using Xamarin.Forms DependencyService to register Fonts at iOS runtime. But first you should download and put fonts file to Cache directory .
Hope it works for you.

how can i use only custom font without family font system on ios

I use CLImageEditor this link, but in the fonts picker it displays the system fonts, I do not want to display it, Because it contains strangely repetitive NewRoman fonts, I have custom fonts, I added to my project and appears in the fonts picker,Custom font that I've added also show with system fonts, how can I hide the system fonts or select specific fonts only, where most of the fonts are similar I do not want to fill font picker withe many fonts.
this code on CLFontPickerView.m :
+ (NSArray*)allFontList
{
NSMutableArray *list = [NSMutableArray array];
for(NSString *familyName in [UIFont familyNames]){
for(NSString *fontName in [UIFont fontNamesForFamilyName:familyName]){
[list addObject:[UIFont fontWithName:fontName size:kCLFontPickerViewConstantFontSize]];
}
}
return [list sortedArrayUsingDescriptors:#[[NSSortDescriptor sortDescriptorWithKey:#"fontName" ascending:YES]]];
}
or you can see it full code from this link

UILabel set bold font with sans-serif

I am trying to set bold font for UILabel as follows :
lblActivities.font = [UIFont fontWithName:#"sans-serif-Bold" size:15.0];
But this is not appearing as bold.
Any suggestions?
1-You need your font in .otf or .ttf copied to your project. For example in Supporting Files.
2 - You need to edit .plist file.
3 - Add "Fonts provided by application" key into your plist and in Item 0 copy the exact filename of the font you copied to your Supporting files WITH extension. For example: "JosefinSansStd-Light_0.otf"
4 - Make sure that the font you imported to your app is being packed into app itself. Do that by selecting your Target, then Build Phases, then Copy Bundle Resources. If you don't see your font in there, drag it from Supporting Files.
5 - Finally, you would like to list all your fonts when the app starts just to see useable name for your font. You will do that with this little piece of code:
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);
}
Search for your font in printed results, for example, I would search for "Josefin" and I would see that actual font name is "JosefinSansStd-Light". After that you only need to use that font by:
UIFont *customFont = [UIFont fontWithName:#"JosefinSansStd-Light" size:20];
In iOS8 you add your fonts directly to the project and they are visible in the interface builder. Modify your code to account for this but programmatically setting font for iOS7 and selecting it in xCode6 interface builder. PS. Interface builder in xCode6 gives you the correct font name that you can copy-paste into the code below.
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
if(SYSTEM_VERSION_LESS_THAN(#"8.0"))
{
UIFont *customFont = [UIFont fontWithName:#"OpenSans-Light" size:32];
self.registerLabel.font = customFont;
}
Hope this helps, cheers.
For More Information check This Post
you have direct option in Xcode
1. select the label on view controller
2. on your right hand side panel select attribute inspector .
3. select font text-box link
4. a alert box appear select font dropdownlist
5 select custom from that list
6 set your style bold from style dropdown
try this may be help you. Make sure the font name is correct or available in your application.
[lblActivities setFont:[UIFont fontWithName:#"sans-serif-Bold" size:15.0]];
The Font which you describe is not available in apple library by Default you have to use custom font for this.
see Below link
Using custom font in a UIWebView

Unable to set custom font for the UILabel in XCode

I am unable to set custom font for the UILabel in XCode.
This is what I've tried:
Download "JennaSue" font -- http://www.dafont.com/jenna-sue.font
Open "app-info.plist" under "Supporting Files" folder
Add new row in the list with key "Fonts provided by application"
In this array add "JennaSue.ttf"
Use it in the code like this:
self.someLabel.font = [UIFont fontWithName:#"JennaSue" size:14];
And nothing happens -- the default font is visible.
Why? What am I doing wrong? How can I fix it?
Be sure your font is in Bundle Resources. For some reason Xcode it is not importing custom font properly most of the time:
I've got the font working:
Example code: here
Go to your project's info.plist file,
Right click and select Add row,
Type Fonts provided by application in the new row,
Type in the desired font name as items for this key.
Drag and drop the font file into the project,
Apply it to the text you want:
someLabel.font = [UIFont fontWithName:#"JennaSue" size: 12.0];
I think you've missed step 5 up there.
Update: When doing step 5, remember to check the marks for copying the actual file into project directory:
Remember to clean your project by pressing "command+alt+shift+K" (IRRC!)
And then go to your
and then go to your project's Build Phases, and make sure you can see your .ttf file file among the resource files:
P.S. I'm not on my Mac at the moment, so I used screenshots from this tutorial. That's why I grayed out the unnecessary lines for your issue.
Check this code:
NSArray *names = [UIFont familyNames];
NSLog(#"Font FamilyNames : ");
for (NSString *name in names) {
NSLog(#"Font Family: %#",name);
NSArray *fontFaces = [UIFont fontNamesForFamilyName:name];
for (NSString *fname in fontFaces) {
NSLog(#" %#",fname);
}
}
self.someLabel.font = [UIFont fontWithName:#"use correct name" size:self.someLabel.font.pointSize];
and use the same name printed with NSLog.
After adding custom font to Xcode don't forget to add font to plist.
Project settings > Info > Custom IOS target properties
Add property Fonts provided by application and type your custom font(filename of font file).
Then you can use that code example
self.someLabel.font = [UIFont fontWithName:#"JennaSue" size:14];
Notice: make sure that you use right font name in code. To do that you should add this font to your Mac's font book, open font book, choose that font and check the right name font.
Hope this helps
self.someLabel.font = [UIFont fontWithName:#"JennaSue.ttf" size:self.someLabel.font.pointSize];
i used following code and it's done
UILabel * lblTest = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 200, 100)];
lblTest.font = [UIFont fontWithName:#"JennaSue" size:25.0];
lblTest.text = #"Hello World";
[self.view addSubview:lblTest];
and if still not working looking at your system font book and search that font and That Font you have to use to get it work
also try this lblTest.font = [UIFont fontWithName:#"Jenna Sue" size:25.0];
The font could be corrupted or something. I tried the solutions provided by Gabriel.Massana & Neeku and it worked on some fonts. Try adding the font to your Mac. If it showed verification problem, most probably it's not gonna work in your app. Hope this helps
is the file visible in Compile Source now…if yes then you may have the font name wrong..sometimes the font names are different then their file name…try running a
for (NSString *familyName in [UIFont familyNames])
{
for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName])
{
NSLog(#"%#", fontName);
}
}
this lines of code..you will be able to see the actual name of the font and use that name instead
Here is #Ritu's answer in Swift 2. Just put this in your AppDelegate, or in viewDidLoad method of your View Controller:
let names = UIFont.familyNames()
for name in names {
print("Font Family: \(name)")
let fontFaces = UIFont.fontNamesForFamilyName(name)
for fname in fontFaces {
print(" \(fname)")
}
}
You will have all your font names in console log, just copy and paste the one you need in your code.

Possible to detect Bold Text setting in Settings > Accessibility?

With iOS 7, it's possible to code your app to respect the user's setting for Dynamic Type - larger or smaller font sizes. You use the method preferredFontForTextStyle: and then listen to notifications in order to update the UI if the user changes the setting while your app is running. I am wondering if it's possible to do the same thing with the accessibility option "Bold Text" found in Settings > Accessibility. I realized that the Bold Text option actually requires you to restart the device, so there should be no need to listen to notifications because your app will be killed and relaunched anyways.
This is what I ultimately want to accomplish: I would like to change the navigation bar title text to a lighter style font. It may not be the default System font - it could be any font iOS can display, but I'll probably use HelveticaNeue-Light. I would also like to respect the user's preference for Bold Text. If it's enabled, I want to change the title text to a heavier weight of that same font - just like iOS does by default even though the default is already quite heavy - Helvetica Neue Medium. Indeed it does make it a little bit heavier when enabled. I want to do the same with a different font.
Here's what I'm doing to change it, but this obviously will be fixed no matter what the bold setting is:
[self.navigationController.navigationBar setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys: [UIFont fontWithName:#"HelveticaNeue-Light" size:17], [NSFontAttributeName, nil]];
I may have a solution but it seems to be a bad approach. I'm making a new font with a fixed size from the preferredFont for subheadline. This does almost exactly what I want - it automatically takes care of font-weight based on the Bold Text setting (HelveticaNeueRegular [I actually want Light] when disabled, HelveticaNeueMedium when enabled), but won't work for a different typeface. Perhaps there is a better approach?
UIFont *subtitleFont = [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline];
UIFont *titleFont = [subtitleFont fontWithSize:17];
[self.navigationController.navigationBar setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:titleFont, NSFontAttributeName, nil]];
As of iOS 8, it is possible to detect whether the user has enabled Bold Text in Settings using UIAccessibility.isBoldTextEnabled (docs) and UIAccessibility.boldTextStatusDidChangeNotification (docs).
For apps that also require iOS 7 support, I’ve written an elegant one-liner that works on iOS 7 & 8 with Helvetica Neue and even on iOS 9 with the San Francisco typeface, based on the fact that standard-weight fonts are commonly referred to as the “Regular” weight, and that body text uses this weight for readability:
Objective-C:
BOOL hasBoldText = ![[UIFont preferredFontForTextStyle:UIFontTextStyleBody].fontName hasSuffix:#"-Regular"];
Swift:
let hasBoldText = !UIFont.preferredFontForTextStyle(UIFontTextStyleBody).fontName.hasSuffix("-Regular")
You can use UIFontDescriptor for that:
UIFontDescriptor *fontDescriptor = [UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleSubheadline];
UIFont *font = [UIFont fontWithDescriptor:fontDescriptor size:17]; // better to use a constant
If you want to change when the font size changes, you can observe the UIApplicationContentSizeDidChangeNotification. I'm not sure if the Bold Text setting also sends this notification, but you can always update on applicationWillEnterForeground:. 99% of the time you update unnecessarily that way, but it should work if the user does decide to change it.
I found another solution. Just parse the current title font to see if it contains the substring 'bold' and if it does not find it, then you know Bold Text is disabled, and you can apply your custom font. Note that this would stop working if Apple changed the heading weight. For example, took it down one notch to Regular and Medium instead of Medium and Bold. And if Apple changes the font family, your fixed font won't match it obviously. But it doesn't seem to be a terrible solution.
UIFont *currentTitleFont = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
//if Bold Text is disabled
if ([currentTitleFont.fontName rangeOfString:#"bold" options:NSCaseInsensitiveSearch].location == NSNotFound) {
UIFont *titleFont = [UIFont fontWithName:#"HelveticaNeue-Light" size:17];
[self.navigationController.navigationBar setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:titleFont, NSFontAttributeName, nil]];
}
else {
//put custom font here for when Bold Text is enabled, or do nothing to get the default
}
In iOS 7 and up, I noticed that the UIFontTextStyleHeadline is: HelveticaNeueInterface-Heavy.
I modified the op's response as follows:
UIFont *currentTitleFont = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
//if Bold Text is disabled
if ([currentTitleFont.fontName rangeOfString:#"bold" options:NSCaseInsensitiveSearch].location == NSNotFound && [currentTitleFont.fontName rangeOfString:#"heavy" options:NSCaseInsensitiveSearch].location == NSNotFound) {
UIFont *titleFont = [UIFont fontWithName:#"HelveticaNeue-Light" size:17];
[self.navigationController.navigationBar setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:titleFont, NSFontAttributeName, nil]];
}
else {
//put custom font here for when Bold Text is enabled, or do nothing to get the default
}
Try this one. It works for me.
let hasBoldText = UIFont.preferredFont(forTextStyle: UIFont.TextStyle.body).fontName.contains("bold")
UIFont.preferredFont(forTextStyle: UIFont.TextStyle.body).fontName
11.4 12.0
".SFUIText"
".SFUIText-Semibold"
13.3

".SFUI-Regular"

".SFUI-Semibold"

Resources