首先先把.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
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];
I just want to thank you for sharing your information and your site or blog this is simple but nice Information I’ve ever seen i like it i learn something today. Apple Enterprise Account
回覆刪除