iOS开发 之字体类型的设置与选择

声明:
    文章转自新浪博主:Apple_ 小熊猫    原文地址:http://blog.sina.com.cn/s/blog_b22973cf0101auqv.html。转载时请附带声明。


 

ios中的字体:

    字体是图形用户界面显示文本的基础。Cocoa在UIKit框架中为开发者提供了高层次的API以及方便的枚举、加载和使用字体。Cocoa Touch 使用UIFont 类来封装字体。每个ios设备都内置了系统字体。字体被组织成字体族科(Families),每个族科又包含字样(Faces)。例如,Helvetica 是一个字体族科,Helvetica Bold是Helvetica族科中的一个字样。要加载字体,你必须知道字体的字样(字体的名字),要知道字样,你必须知道它的族科。怎么获取系统字体的族科呢,我们可以循环输出系统字体族科,使用UIFont类的familyNames类方法,通过这个类方法得到字体族科名字然后用UIFont类的fontNamesForFamilyName:类方法,传递family name作为参数,并返回一个字体名称的数组(array):

 

[plain]  view plain copy
  1. (void)enumerateFonts{  
  2.       for(NSString *familyName in [UIFont familyNames]){  
  3.       NSLog(@"Font FamilyName %@",familyName); //*输出字体族科名字  
  4.   
  5.         for(NSString *fontName in [UIFont fontNameForFamilyName:familyName]){  
  6.             NSLog(@"\t%@",fontName);         //*输出字体族科下字样名字  
  7.          
  8.      
  9.  

 

 

在ios模拟器上运行代码,得到如下结果:

...
Font Family = Geeza Pro
GeezaPro
GeezaPro-Bold
Font Family = Helvetica Neue
HelveticaNeue-Italic
HelveticaNeue-Bold
HelveticaNeue-BoldItalic
HelveticaNeue

...

字体族科后面加-Bold就是加粗 加-Oblique就是倾斜等


iPhone 5.0 iPad 5.0
Font Families: 58 Font Families: 58
Academy Engraved LET
AcademyEngravedLetPlain AcademyEngravedLetPlain
American Typewriter
AmericanTypewriter-CondensedLight AmericanTypewriter-CondensedLight
AmericanTypewriter-Light AmericanTypewriter-Light
AmericanTypewriter AmericanTypewriter
AmericanTypewriter-Condensed AmericanTypewriter-Condensed
AmericanTypewriter-Bold AmericanTypewriter-Bold
AmericanTypewriter-CondensedBold AmericanTypewriter-CondensedBold
Apple Color Emoji
AppleColorEmoji AppleColorEmoji
Apple SD Gothic Neo
AppleSDGothicNeo-Medium AppleSDGothicNeo-Medium
AppleSDGothicNeo-Bold AppleSDGothicNeo-Bold
Arial
ArialMT ArialMT
Arial-ItalicMT Arial-ItalicMT
Arial-BoldMT Arial-BoldMT
Arial-BoldItalicMT Arial-BoldItalicMT
Arial Hebrew
ArialHebrew ArialHebrew
ArialHebrew-Bold ArialHebrew-Bold
Arial Rounded MT Bold
ArialRoundedMTBold ArialRoundedMTBold
Bangla Sangam MN
BanglaSangamMN-Bold BanglaSangamMN-Bold
BanglaSangamMN BanglaSangamMN
Baskerville
Baskerville Baskerville
Baskerville-Italic Baskerville-Italic
Baskerville-SemiBold Baskerville-SemiBold
Baskerville-SemiBoldItalic Baskerville-SemiBoldItalic
Baskerville-Bold Baskerville-Bold
Baskerville-BoldItalic Baskerville-BoldItalic
Bodoni 72
BodoniSvtyTwoITCTT-Book BodoniSvtyTwoITCTT-Book
BodoniSvtyTwoITCTT-BookIta BodoniSvtyTwoITCTT-BookIta
BodoniSvtyTwoITCTT-Bold BodoniSvtyTwoITCTT-Bold
Bodoni 72 Oldstyle
BodoniSvtyTwoOSITCTT-Book BodoniSvtyTwoOSITCTT-Book
BodoniSvtyTwoOSITCTT-BookIt BodoniSvtyTwoOSITCTT-BookIt
BodoniSvtyTwoOSITCTT-Bold BodoniSvtyTwoOSITCTT-Bold
Bodoni 72 Smallcaps
BodoniSvtyTwoSCITCTT-Book BodoniSvtyTwoSCITCTT-Book
Bodoni Ornaments
BodoniOrnamentsITCTT BodoniOrnamentsITCTT
Bradley Hand
BradleyHandITCTT-Bold BradleyHandITCTT-Bold
Chalkboard SE
ChalkboardSE-Light ChalkboardSE-Light
ChalkboardSE-Regular ChalkboardSE-Regular
ChalkboardSE-Bold ChalkboardSE-Bold
Chalkduster
Chalkduster Chalkduster
Cochin
Cochin Cochin
Cochin-Italic Cochin-Italic
Cochin-Bold Cochin-Bold
Cochin-BoldItalic Cochin-BoldItalic
Copperplate
Copperplate-Light Copperplate-Light
Copperplate Copperplate
Copperplate-Bold Copperplate-Bold
Courier
Courier Courier
Courier-Oblique Courier-Oblique
Courier-Bold Courier-Bold
Courier-BoldOblique Courier-BoldOblique
Courier New
CourierNewPSMT CourierNewPSMT
CourierNewPS-BoldMT CourierNewPS-BoldMT
CourierNewPS-BoldItalicMT CourierNewPS-BoldItalicMT
CourierNewPS-ItalicMT CourierNewPS-ItalicMT
DB LCD Temp
DBLCDTempBlack DBLCDTempBlack
Devanagari Sangam MN
DevanagariSangamMN DevanagariSangamMN
DevanagariSangamMN-Bold DevanagariSangamMN-Bold
Didot
Didot Didot
Didot-Italic Didot-Italic
Didot-Bold Didot-Bold
Euphemia UCAS
EuphemiaUCAS EuphemiaUCAS
EuphemiaUCAS-Italic EuphemiaUCAS-Italic
EuphemiaUCAS-Bold EuphemiaUCAS-Bold
Futura
Futura-Medium Futura-Medium
Futura-MediumItalic Futura-MediumItalic
Futura-CondensedMedium Futura-CondensedMedium
Futura-CondensedExtraBold Futura-CondensedExtraBold
Geeza Pro
GeezaPro GeezaPro
GeezaPro-Bold GeezaPro-Bold
Georgia
Georgia Georgia
Georgia-Italic Georgia-Italic
Georgia-Bold Georgia-Bold
Georgia-BoldItalic Georgia-BoldItalic
Gill Sans
GillSans-Light GillSans-Light
GillSans-LightItalic GillSans-LightItalic
GillSans GillSans
GillSans-Italic GillSans-Italic
GillSans-Bold GillSans-Bold
GillSans-BoldItalic GillSans-BoldItalic
Gujarati Sangam MN
GujaratiSangamMN GujaratiSangamMN
GujaratiSangamMN-Bold GujaratiSangamMN-Bold
Gurmukhi MN
GurmukhiMN GurmukhiMN
GurmukhiMN-Bold GurmukhiMN-Bold
Heiti SC
STHeitiSC-Light STHeitiSC-Light
STHeitiSC-Medium STHeitiSC-Medium
Heiti TC
STHeitiTC-Light STHeitiTC-Light
STHeitiTC-Medium STHeitiTC-Medium
Helvetica
Helvetica-Light Helvetica-Light
Helvetica-LightOblique Helvetica-LightOblique
Helvetica Helvetica
Helvetica-Oblique Helvetica-Oblique
Helvetica-Bold Helvetica-Bold
Helvetica-BoldOblique Helvetica-BoldOblique
Helvetica Neue
HelveticaNeue-UltraLight HelveticaNeue-UltraLight
HelveticaNeue-UltraLightItalic HelveticaNeue-UltraLightItalic
HelveticaNeue-Light HelveticaNeue-Light
HelveticaNeue-LightItalic HelveticaNeue-LightItalic
HelveticaNeue HelveticaNeue
HelveticaNeue-Italic HelveticaNeue-Italic
HelveticaNeue-Medium HelveticaNeue-Medium
HelveticaNeue-Bold HelveticaNeue-Bold
HelveticaNeue-BoldItalic HelveticaNeue-BoldItalic
HelveticaNeue-CondensedBold HelveticaNeue-CondensedBold
HelveticaNeue-CondensedBlack HelveticaNeue-CondensedBlack
Hiragino Kaku Gothic ProN
HiraKakuProN-W3 HiraKakuProN-W3
HiraKakuProN-W6 HiraKakuProN-W6
Hiragino Mincho ProN
HiraMinProN-W3 HiraMinProN-W3
HiraMinProN-W6 HiraMinProN-W6
Hoefler Text
HoeflerText-Regular HoeflerText-Regular
HoeflerText-Italic HoeflerText-Italic
HoeflerText-Black HoeflerText-Black
HoeflerText-BlackItalic HoeflerText-BlackItalic
Kailasa
Kailasa Kailasa
Kailasa-Bold Kailasa-Bold
Kannada Sangam MN
KannadaSangamMN KannadaSangamMN
KannadaSangamMN-Bold KannadaSangamMN-Bold
Malayalam Sangam MN
MalayalamSangamMN MalayalamSangamMN
MalayalamSangamMN-Bold MalayalamSangamMN-Bold
Marion
Marion-Regular Marion-Regular
Marion-Italic Marion-Italic
Marion-Bold Marion-Bold
Marker Felt
MarkerFelt-Thin MarkerFelt-Thin
MarkerFelt-Wide MarkerFelt-Wide
Noteworthy
Noteworthy-Light Noteworthy-Light
Noteworthy-Bold Noteworthy-Bold
Optima
Optima-Italic Optima-Italic
Optima-Regular Optima-Regular
Optima-Bold Optima-Bold
Optima-BoldItalic Optima-BoldItalic
Optima-ExtraBlack Optima-ExtraBlack
Oriya Sangam MN
OriyaSangamMN OriyaSangamMN
OriyaSangamMN-Bold OriyaSangamMN-Bold
Palatino
Palatino-Roman Palatino-Roman
Palatino-Italic Palatino-Italic
Palatino-Bold Palatino-Bold
Palatino-BoldItalic Palatino-BoldItalic
Papyrus
Papyrus Papyrus
Papyrus-Condensed Papyrus-Condensed
Party LET
PartyLetPlain PartyLetPlain
Sinhala Sangam MN
SinhalaSangamMN SinhalaSangamMN
SinhalaSangamMN-Bold SinhalaSangamMN-Bold
Snell Roundhand
SnellRoundhand SnellRoundhand
SnellRoundhand-Bold SnellRoundhand-Bold
SnellRoundhand-Black SnellRoundhand-Black
Tamil Sangam MN
TamilSangamMN TamilSangamMN
TamilSangamMN-Bold TamilSangamMN-Bold
Telugu Sangam MN
TeluguSangamMN TeluguSangamMN
TeluguSangamMN-Bold TeluguSangamMN-Bold
Thonburi
Thonburi Thonburi
Thonburi-Bold Thonburi-Bold
Times New Roman
TimesNewRomanPSMT TimesNewRomanPSMT
TimesNewRomanPS-ItalicMT TimesNewRomanPS-ItalicMT
TimesNewRomanPS-BoldMT TimesNewRomanPS-BoldMT
TimesNewRomanPS-BoldItalicMT TimesNewRomanPS-BoldItalicMT
Trebuchet MS
TrebuchetMS TrebuchetMS
TrebuchetMS-Italic TrebuchetMS-Italic
TrebuchetMS-Bold TrebuchetMS-Bold
Trebuchet-BoldItalic Trebuchet-BoldItalic
Verdana
Verdana Verdana
Verdana-Italic Verdana-Italic
Verdana-Bold Verdana-Bold
Verdana-BoldItalic Verdana-BoldItalic
Zapf Dingbats
ZapfDingbatsITC ZapfDingbatsITC
Zapfino
Zapfino Zapfino

附带例子:

 

    UILabel *textLabel=[[UILabel alloc]initWithFrame:CGRectMake(10, 100, 300, 50)];

    textLabel.text=@"ThonburiThonburi";

    textLabel.backgroundColor=[UIColor clearColor];

    textLabel.textColor=[UIColor blackColor];

    textLabel.font=[UIFont fontWithName:@"GillSans-BoldItalic" size:20];//直接写入 每个字体族下的小类,即能改变字体。

    [self.view addSubview:textLabel];

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值