Translate

顯示具有 ttf 標籤的文章。 顯示所有文章
顯示具有 ttf 標籤的文章。 顯示所有文章

2013年9月24日 星期二

objective-c TTC to TTF and All iOS6 fonts website

在寫專案的時候美術常常拿很奇怪的字體要我們在App裡面使用
就我自己目前只會使用ttf欓
後來同事上網找到這個好工具
可以把ttc轉ttf
下載鏈結

另外還有個網站很不錯
可以馬上看到內建字型的樣式
website

2013年5月7日 星期二

ios-tips-custom-fonts

參考link

首先先把.ttf檔放進專案裡

確定有勾選Add to targets


Verify the font is in the project. There are two places you can do this.

By selecting the font, and verifying “Target Membership” in the Utilities area.



And By selecting your apps target, selecting the “Build Phases” tab, and verifying that your font is in the “Copy Bundle Resources” section.



And finally, add the font to your Info.plist. Note that most apps change the name of their plist to something like -Info.plist. Add a key of “Fonts provided by application”, and make sure it’s an array, then add your font file name as an item in the array. Make sure you use the exact file name, and that your file name has an all-lowercase extension (.TTF apparently doesn’t work on iPhones, but .ttf does).



Knowing your font
This is where I had some issues. When you add your font you use the file name, but when you use your font you use the font name… The EXACT font name. If you ctrl + click on the .ttf file and select “Get Info”, you can find the “Full Name”. That seems to work with a lot of fonts, but the font I’m using doesn’t work that way. I had to open the .ttf file in the Font Book application, and look at the window header.



Using this name, you can log what font names you have available by using the fontNamesForFamilyName method like so:

NSLog(@"tt0001m_: %@", [UIFont fontNamesForFamilyName:@"Swis721 Lt BT"] ); Which gives the output: 2012-08-24 11:25:10.968 GenericKeychain[7260:c07] tt0001m_: ( "Swiss721BT-Light" )
Using your font programmatically
Say you have a UILabel:

UILabel *myLabel = [[UILabel alloc] init];
[myLabel setText:@"Label Text"];

We set the font of our label by creating a UIFont, and setting it to our label with setFont.
UIFont *swissLight = [UIFont fontWithName:@"Swiss721BT-Light" size:myLabel.font.pointSize]; [myLabel setFont:swissLight];