Translate

2013年4月16日 星期二

Custom Fonts

參考網站

在專案裡面需要用到ttf的字型
所以記錄一下

加入the .ttf檔案到專案裡



確定Add to targets是勾起來的



點選.ttf檔確定右手邊的Target Memvership是打勾的



在回專案的TARGETS->Build Phases->Copy Bundle Resources



最後在專案的info.plist增加Fonts provided by application並加上.ttf的檔案名稱



然後取得.ttf的全名



使用方法
NSLog(@"vagrounded-bold.ttf is %@", [UIFont fontNamesForFamilyName:@"VAGRounded-Bold"] ); NSLog(@"vagrounded-thin.ttf is %@", [UIFont fontNamesForFamilyName:@"VAGROUNDED-Thin"] ); UILabel *lab = [UILabel new]; [lab setFrame:CGRectMake(50, 50, 100, 30)]; UIFont *swissLight = [UIFont fontWithName:@"VAGRounded-Bold" size:20.0f]; [lab setFont:swissLight]; [lab setText:@"GodCam"]; [self.view addSubview:lab]; UILabel *lab2 = [UILabel new]; [lab2 setFrame:CGRectMake(50, 100, 100, 30)]; UIFont *swissLight2 = [UIFont fontWithName:@"VAGROUNDED-Thin" size:20.0f]; [lab2 setFont:swissLight2]; [lab2 setText:@"GodCam"]; [self.view addSubview:lab2]; 2013-04-17 13:48:20.635 UseTTF[787:c07] vagrounded-bold.ttf is ( "VAGRounded-Bold" ) 2013-04-17 13:48:20.636 UseTTF[787:c07] vagrounded-thin.ttf is ( "VAGROUNDED-Thin" )

沒有留言:

張貼留言