info.plist -> add font name to [Fonts provided by application] category
use below code
voidregistFont(conststring&file_name){// get ttf file path
NSString*basePath=[NSStringstringWithUTF8String:file_name.c_str()];NSString*resourcePath=[[NSBundlemainBundle]resourcePath];NSString*fullPath=[resourcePathstringByAppendingPathComponent:basePath];// regist the font
CGDataProviderReffontDataProvider=CGDataProviderCreateWithFilename([fullPathUTF8String]);CGFontRefcustomFont=CGFontCreateWithDataProvider(fontDataProvider);CGDataProviderRelease(fontDataProvider);CFErrorReferror;if(!CTFontManagerRegisterGraphicsFont(customFont,&error)){CFStringReferrorDescription=CFErrorCopyDescription(error);NSLog(@"Failed to load font %s: %@",file_name.c_str(),errorDescription);CFRelease(errorDescription);}elseLog::info_print("registFont %s success",file_name.c_str());CGFontRelease(customFont);}
2.Xcode Bug
Sometimes a font is not registed, although you follow above step. At this times, remove the font’s reference, and then add the reference again.