Question

I am having a font name: HelveticaNeueLTStd-Roman 55.otf. I added it in my info.plist file.

When I write code :

UIFont *fontHalvetikaNeueLTStd = [UIFont fontWithName:@"Helvetica Neue LT Std" size:55];

It works Fyn!

But when I added following Code with Font style, it returns me nil.

UIFont *fontHalvetikaNeueLTStd = [UIFont fontWithName:@"Helvetica Neue LT Std 55 Roman" size:55];

How can I set "Roman 55" style in my Custom Font?

Solved By Adding Following:

Verify Font name By:

NSLog (@"Font families: %@", [UIFont fontNamesForFamilyName:@"Helvetica Neue LT Std"]);

Output:

Font families: (

"HelveticaNeueLTStd-Lt",
"HelveticaNeueLTStd-Roman"

)

Then Set By:

UIFont *fontHalvetikaNeueLTStd = [UIFont fontWithName:@"HelveticaNeueLTStd-Roman" size:size];

Thanks to all your hints.

Était-ce utile?

La solution

Every time when we add custom fonts in our application need to review first about the font name and font full name. please review.

if yes then review font with the name Helvetica Neue LT Std 55 Roman exist in your system or not.

  • Use font file name in plist, and font name in your iOS code.

If you want to know all the load fonts in your app review this code.

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

enter image description here

Autres conseils

Swift code snippet

for family in UIFont.familyNames() {
    print("Font Family = \(family)")
    for name in UIFont.fontNamesForFamilyName(family) {
        print("Font Name = \(name)")
    }
}

Swift 4

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

You need to add the font file with name Helvetica Neue LT Std 55 Roman and add the entry to info plist. It will work fine.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top