How to use custom font in iOS (ex: Helvetica CY.ttf) with Xcode program code

  • I am trying to use the Helvetica CY font in my application. I configured it as recommended by apple docs.
  • A custom font appears in the drop-down list on the Storyboard, but cannot use the same font programmatically in my class file.
  • I have registered all font families available for the application, but " Helvetica CY " is not printed in the console log.

Any help would be appreciated.

Thanks!

+6
source share
5 answers

Simple. Its work for me too in xcode6.1.

Try using the steps:

Step 1: Include Fonts in an Xcode Project

Step 2: Make sure they are included in the goal

Step 3: Double check that your fonts are included as resources in your package

Step 4: Include iOS Custom Fonts in Your Application Plan

Step 5: Find the Font Name

 for (NSString* family in [UIFont familyNames]) { NSLog(@"%@", family); for (NSString* name in [UIFont fontNamesForFamilyName: family]) { NSLog(@" %@", name); } } 

Step 6: Use UIFont and Specify the Font Name

 label.font = [UIFont fontWithName:@"Helvetica CY" size:20]; 
+38
source

Apple provides a set of fonts to customize our application, and also allows you to add custom fonts.

Steps

  • Copy the font files (.ttf or .otf) into the main package.

  • Add the file names to info.plist as a new array called "Fonts provided by the application."

  • It is very important to add a script font name to this message array. This means that each font has a font name (with extension) and its postscript name in the info.plist file.

  • To find the name of the Post script, simply open the Fontbook application in the poppy, and then add the font file. After adding the font file to the font book, just browse the information tab of this font, there you can find the name Post script.

  • Usage is quite simple, use post script font name,

     nameLabel.font = [UIFont fontWithName:@"HelveticaCY-Plain" size:22]; 

enter image description here

+20
source

I made the same mistake. The key is the answer above:

 for (NSString* family in [UIFont familyNames]) { NSLog(@"%@", family); for (NSString* name in [UIFont fontNamesForFamilyName: family]) { NSLog(@" %@", name); } } 

I included the GOTHIC.TTF file in my project folder.

And in my Info.plist, I included GOTHIC.TTF in "Fonts provided by the application."

But surprise! The font is not called "GOTHIC", but "CenturyGothic".

 [cell.textLabel setFont:[UIFont fontWithName:@"CenturyGothic" size:24]]; 
+1
source

just go to this link and follow the steps. it has all the steps http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/

+1
source

If someone is interested in Swift 3 code to get fonts:

 for family in UIFont.familyNames { print("Family: \(family)") for name in UIFont.fontNames(forFamilyName: family) { print("Name: \(name)") } } 
0
source

Source: https://habr.com/ru/post/977525/


All Articles