2012年4月23日 星期一

帥氣的彼得潘簽名

1. 將字型檔加入專案
   加入DFLiuStd-W3.otf

2. 設定Font provided by application
    於其中輸入字型檔的檔名


3.  設定Label的font
for (NSString *familyName in [UIFont familyNames])
{
NSLog(@"familyName %@", familyName);
for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName])
{
NSLog(@"%@", fontName);
}
}
UILabel *bookLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 300, 30)];
[self.view addSubview:bookLabel];
bookLabel.text = @"App程式設計入門";
UILabel *authorLabel = [[UILabel alloc] initWithFrame:CGRectMake(160, 60, 120, 30)];
[self.view addSubview:authorLabel];
authorLabel.text = @"彼得潘";
UIFont *newFont = [UIFont fontWithName:@"DFLiuStd-W3" size:30];
bookLabel.font = newFont;
authorLabel.font = newFont;
view raw gistfile1.m hosted with ❤ by GitHub
利用UIFont的fontWithName:size:設定字型

+ (UIFont *)fontWithName:(NSString *)fontName size:(CGFloat)fontSize;
view raw UIFont.h hosted with ❤ by GitHub
其中的關鍵在於傳入的fontName。
我們利用fontNamesForFamilyName:列出所有的font,
從中找到DFLiuStd-W3。


執行App:


沒有留言:

張貼留言