IOS Custom font

Source: Internet
Author: User

Introduction:

The default app font is easy to understand, and a personalized experience is also a good choice.

Refer:

Http://www.16kan.com/post/218270.html

Http://blog.csdn.net/frankwun/article/details/7688950

Where is the font?

Mac has a built-in app calledFont volume. After opening this application, you can see the fonts currently embedded in the system. IOS supports two display formats:OTFAndTTF.

PreferredOTF.

How to configure it?

Step 1:

Drag the font to be used to the project.

Step 2:

Add the fonts provided by application item to info. plist and add an item value to the file name of the added font file.

How to use it?

Note that the font file name is not the actual name.

The real name can be seen when you view the detailed parameters of a field in the font volume. For example:

You can also obtain the code based on the path of the font file in the application (not very accurate, and may need to adjust it manually occasionally ):

NSString *fontPath = [[NSBundle mainBundle] pathForResource:fontFileNameArray[i] ofType:nil];NSURL *url = [NSURL fileURLWithPath:fontPath];CGDataProviderRef fontDataProvider = CGDataProviderCreateWithURL((__bridge CFURLRef)url);if (fontDataProvider == NULL){    break;}CGFontRef newFont = CGFontCreateWithDataProvider(fontDataProvider);CGDataProviderRelease(fontDataProvider);if (newFont == NULL){    break;}CFStringRef fontName = CGFontCopyFullName(newFont);NSString *fontNameString = (__bridge id)(fontName);if ([fontNameString isEqualToString:@"Yuppy SC Regular"]) {    fontNameString = @"YuppySC-Regular";}[fontNameMDic setObject:fontNameString forKey:fontFileNameArray[i]];CFRelease(fontName);CGFontRelease(newFont);

The following code lists the font names that can be used in IOS.

NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];NSArray *fontNames;NSInteger indFamily, indFont;for(indFamily=0;indFamily<[familyNames count];++indFamily){    NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);    fontNames =[[NSArray alloc]initWithArray:[UIFont fontNamesForFamilyName:[familyNames objectAtIndex:indFamily]]];    for(indFont=0; indFont<[fontNames count]; ++indFont)    {        NSLog(@" Font name: %@",[fontNames objectAtIndex:indFont]);    }}

Summary:

The only downside is that the font data packets occupy the app size. This problem remains to be solved.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.