1、从网上下载所需字体的TTF文件。将字体所对应的TTF文件拖入项目中。
2、然后在info.plist中添加一个新的键Fonts provided by application, NSArray类型的, 在其对应的item里面的string值为**.TTF,如图:
3、接下来就是要知道对应字体的名字FontName了。一个字体文件包括以下几个内容:文件名、字体名称、字体具体名称,我们只有文件名,不知道字体名称是什么,更不知道具体的名称,那么我们就需要写代码获得具体的字体名称。方法如下:
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(160, 32, WIDTH - 320, 50)];
label.text = @"陆垚知马俐";
label.textColor = [UIColor whiteColor];
[self.view addSubview:label];
NSArray *familyNames = [UIFont familyNames];
for (NSString *familyName in familyNames)
{
NSArray *fontNames = [UIFont fontNamesForFamilyName:familyName];
for (NSString *fontName in fontNames)
{
printf("\tFont: %s \n", [fontName UTF8String]);
}
}
看一下打印结果吧?
4、现在可以知道文字包里面的字体名称了吧?接下来使用就可以咯:
label.font = [UIFont fontWithName:@"Georgia-Bold" size:18.0];
我们在开发中很多时候要设置UIlabel,UIbutton,UItextfield的字体,这个时候我们就需要用到UIFont,下面简单介绍一下UIFont的用法,仅供参考。
UIFont用于获取和设置字体信息。这个类提供用于输出的字体的属性和字型信息。我们可以把其对象像参数一样传入函数中。
一般而言我们不需要用alloc,int方法初始化UIFont对象,我们用UIFont大部分的时候是用其类方法,这些方法会设置对象的属性,且返回一个字体对象。
下面两个函数创建字体:
+fontWithName:(NSString *)fontName size:(CGFloat) fontSize 创建并且返回一个指定字体类型和大小的字体对象,fontName指定字体集的名字和风格(例如宋体,楷书等这一类型的),fontsize设置字体的大小。
-fontWithSize:返回字体的大小
上面我们提到我们需要设置字体集,在IOS系统中我们用到的字体包含以下几种 :
Font: Copperplate-Light
Font: Copperplate
Font: Copperplate-Bold
Font: IowanOldStyle-Italic
Font: IowanOldStyle-Roman
Font: IowanOldStyle-BoldItalic
Font: IowanOldStyle-Bold
Font: KohinoorTelugu-Regular
Font: KohinoorTelugu-Medium
Font: KohinoorTelugu-Light
Font: CourierNewPS-BoldMT
Font: CourierNewPS-ItalicMT
Font: CourierNewPSMT
Font: CourierNewPS-BoldItalicMT
Font: GillSans-Italic
Font: GillSans-Bold
Font: GillSans-BoldItalic
Font: GillSans-LightItalic
Font: GillSans
Font: GillSans-Light
Font: GillSans-SemiBold
Font: GillSans-SemiBoldItalic
Font: GillSans-UltraBold
Font: AppleSDGothicNeo-Bold
Font: AppleSDGothicNeo-Thin
Font: AppleSDGothicNeo-UltraLight
Font: AppleSDGothicNeo-Regular
Font: AppleSDGothicNeo-Light
Font: AppleSDGothicNeo-Medium
Font: AppleSDGothicNeo-SemiBold
Font: MarkerFelt-Thin
Font: MarkerFelt-Wide
Font: Thonburi
Font: Thonburi-Bold
Font: Thonburi-Light
Font: FZLTXIHJW--GB1-0
Font: AvenirNextCondensed-BoldItalic
Font: AvenirNextCondensed-Heavy
Font: AvenirNextCondensed-Medium
Font: AvenirNextCondensed-Regular
Font: AvenirNextCondensed-HeavyItalic
Font: AvenirNextCondensed-MediumItalic
Font: AvenirNextCondensed-Italic
Font: AvenirNextCondensed-UltraLightItalic
Font: AvenirNextCondensed-UltraLight
Font: AvenirNextCondensed-DemiBold
Font: AvenirNextCondensed-Bold
Font: AvenirNextCondensed-DemiBoldItalic
Font: TamilSangamMN
Font: TamilSangamMN-Bold
Font: HelveticaNeue-Italic
Font: HelveticaNeue-Bold
Font: HelveticaNeue-UltraLight
Font: HelveticaNeue-CondensedBlack
Font: HelveticaNeue-BoldItalic
Font: HelveticaNeue-CondensedBold
Font: HelveticaNeue-Medium
Font: HelveticaNeue-Light
Font: HelveticaNeue-Thin
Font: HelveticaNeue-ThinItalic
Font: HelveticaNeue-LightItalic
Font: HelveticaNeue-UltraLightItalic
Font: HelveticaNeue-MediumItalic
Font: HelveticaNeue
Font: GurmukhiMN-Bold
Font: GurmukhiMN
Font: TimesNewRomanPSMT
Font: TimesNewRomanPS-BoldItalicMT
Font: TimesNewRomanPS-ItalicMT
Font: TimesNewRomanPS-BoldMT
Font: Georgia-BoldItalic
Font: Georgia
Font: Georgia-Italic
Font: Georgia-Bold
Font: AppleColorEmoji
Font: ArialRoundedMTBold
Font: Kailasa-Bold
Font: Kailasa
Font: KohinoorDevanagari-Light
Font: KohinoorDevanagari-Regular
Font: KohinoorDevanagari-Semibold
Font: KohinoorBangla-Semibold
Font: KohinoorBangla-Regular
Font: KohinoorBangla-Light
Font: ChalkboardSE-Bold
Font: ChalkboardSE-Light
Font: ChalkboardSE-Regular
Font: SinhalaSangamMN-Bold
Font: SinhalaSangamMN
Font: PingFangTC-Medium
Font: PingFangTC-Regular
Font: PingFangTC-Light
Font: PingFangTC-Ultralight
Font: PingFangTC-Semibold
Font: PingFangTC-Thin
Font: GujaratiSangamMN-Bold
Font: GujaratiSangamMN
Font: DamascusLight
Font: DamascusBold
Font: DamascusSemiBold
Font: DamascusMedium
Font: Damascus
Font: Noteworthy-Light
Font: Noteworthy-Bold
Font: GeezaPro
Font: GeezaPro-Bold
Font: Avenir-Medium
Font: Avenir-HeavyOblique
Font: Avenir-Book
Font: Avenir-Light
Font: Avenir-Roman
Font: Avenir-BookOblique
Font: Avenir-Black
Font: Avenir-MediumOblique
Font: Avenir-BlackOblique
Font: Avenir-Heavy
Font: Avenir-LightOblique
Font: Avenir-Oblique
Font: AcademyEngravedLetPlain
Font: DiwanMishafi
Font: Futura-CondensedMedium
Font: Futura-CondensedExtraBold
Font: Futura-Medium
Font: Futura-MediumItalic
Font: Farah
Font: KannadaSangamMN
Font: KannadaSangamMN-Bold
Font: ArialHebrew-Bold
Font: ArialHebrew-Light
Font: ArialHebrew
Font: ArialMT
Font: Arial-BoldItalicMT
Font: Arial-BoldMT
Font: Arial-ItalicMT
Font: PartyLetPlain
Font: Chalkduster
Font: HoeflerText-Italic
Font: HoeflerText-Regular
Font: HoeflerText-Black
Font: HoeflerText-BlackItalic
Font: Optima-Regular
Font: Optima-ExtraBlack
Font: Optima-BoldItalic
Font: Optima-Italic
Font: Optima-Bold
Font: Palatino-Bold
Font: Palatino-Roman
Font: Palatino-BoldItalic
Font: Palatino-Italic
Font: FZLTZHK--GBK1-0
Font: MalayalamSangamMN-Bold
Font: MalayalamSangamMN
Font: AlNile-Bold
Font: AlNile
Font: BradleyHandITCTT-Bold
Font: PingFangHK-Ultralight
Font: PingFangHK-Semibold
Font: PingFangHK-Thin
Font: PingFangHK-Light
Font: PingFangHK-Regular
Font: PingFangHK-Medium
Font: LaoSangamMN
Font: Helvetica-Bold
Font: Helvetica
Font: Helvetica-LightOblique
Font: Helvetica-Oblique
Font: Helvetica-BoldOblique
Font: Helvetica-Light
Font: Courier-BoldOblique
Font: Courier
Font: Courier-Bold
Font: Courier-Oblique
Font: Cochin-Bold
Font: Cochin
Font: Cochin-Italic
Font: Cochin-BoldItalic
Font: Trebuchet-BoldItalic
Font: TrebuchetMS
Font: TrebuchetMS-Bold
Font: TrebuchetMS-Italic
Font: HiraMinProN-W6
Font: HiraMinProN-W3
Font: DevanagariSangamMN
Font: DevanagariSangamMN-Bold
Font: OriyaSangamMN
Font: OriyaSangamMN-Bold
Font: SnellRoundhand-Bold
Font: SnellRoundhand
Font: SnellRoundhand-Black
Font: ZapfDingbatsITC
Font: BodoniSvtyTwoITCTT-Bold
Font: BodoniSvtyTwoITCTT-Book
Font: BodoniSvtyTwoITCTT-BookIta
Font: Verdana-Italic
Font: Verdana-BoldItalic
Font: Verdana
Font: Verdana-Bold
Font: AmericanTypewriter-CondensedLight
Font: AmericanTypewriter
Font: AmericanTypewriter-CondensedBold
Font: AmericanTypewriter-Light
Font: AmericanTypewriter-Bold
Font: AmericanTypewriter-Condensed
Font: AvenirNext-UltraLight
Font: AvenirNext-UltraLightItalic
Font: AvenirNext-Bold
Font: AvenirNext-BoldItalic
Font: AvenirNext-DemiBold
Font: AvenirNext-DemiBoldItalic
Font: AvenirNext-Medium
Font: AvenirNext-HeavyItalic
Font: AvenirNext-Heavy
Font: AvenirNext-Italic
Font: AvenirNext-Regular
Font: AvenirNext-MediumItalic
Font: Baskerville-Italic
Font: Baskerville-SemiBold
Font: Baskerville-BoldItalic
Font: Baskerville-SemiBoldItalic
Font: Baskerville-Bold
Font: Baskerville
Font: KhmerSangamMN
Font: Didot-Italic
Font: Didot-Bold
Font: Didot
Font: SavoyeLetPlain
Font: BodoniOrnamentsITCTT
Font: Symbol
Font: Menlo-Italic
Font: Menlo-Bold
Font: Menlo-Regular
Font: Menlo-BoldItalic
Font: BodoniSvtyTwoSCITCTT-Book
Font: Papyrus
Font: Papyrus-Condensed
Font: HiraginoSans-W3
Font: HiraginoSans-W6
Font: PingFangSC-Ultralight
Font: PingFangSC-Regular
Font: PingFangSC-Semibold
Font: PingFangSC-Thin
Font: PingFangSC-Light
Font: PingFangSC-Medium
Font: EuphemiaUCAS-Italic
Font: EuphemiaUCAS
Font: EuphemiaUCAS-Bold
Font: Zapfino
Font: BodoniSvtyTwoOSITCTT-Book
Font: BodoniSvtyTwoOSITCTT-Bold
Font: BodoniSvtyTwoOSITCTT-BookIt
UIFont fontWithName 后不知道字体的名字,看了下面的全解决!