|
|
#1 |
|
Using Custom Fonts
Is it true that you can't use custom fonts in apps? By custom, I mean any TTF that's not already available on the system?
|
|
|
|
0
|
|
|
#2 |
|
Yes. There is no way to load them.
|
|
|
|
0
|
|
|
#3 |
|
This is incorrect I am currently loading custom .ttf's and using them to draw text onto the screen with several of my applications. Look into CGFontCreateWithDataProvider and how to draw text in a - (void)drawRect
CGRect)rect method.Hope this helps! -Brent |
|
|
|
0
|
|
|
#4 |
|
Well you learn something every day. Last time this was asked no-one had a solution. Of course you cannot distribute the fonts with your application without an appropriate license...
|
|
|
|
0
|
|
|
#5 |
|
This is an important point that I think needs re-iterating. If you're using a custom font that you've purchased you need to check the license under which you purchased it as it will almost certainly preclude you from distributing the font itself.
|
|
|
|
0
|
|
|
#6 |
|
Thanks Brent! I'll look into this. And, of course, make sure I'm using a font with an appropriate license.
|
|
|
|
0
|
|
|
#7 | |
|
Quote:
Since the NDA is lifted I would like to give you a little more of my code so you don't have to go through all of the pains I did trying to do this task. 1. I am using this code in a UILabel class override, which isn't really necessary at all you could get the same functionality out of a UIView override with a few more member variables. 2. Here is how I load the font: Code:
// Get the path to our custom font and create a data provider. NSString *fontPath = [[NSBundle mainBundle] pathForResource:@"FontToLoad" ofType:@"ttf"]; CGDataProviderRef fontDataProvider = CGDataProviderCreateWithFilename([fontPath UTF8String]); // Create the font with the data provider, then release the data provider. CGFontRef customFont = CGFontCreateWithDataProvider(fontDataProvider); CGDataProviderRelease(fontDataProvider); // Create the matrix to flip any text drawn to a readable orientation. CGAffineTransform textTransform = CGAffineTransformMake(1.0, 0.0, 0.0, -1.0, 0.0, 0.0); 3. Now after that is all completed you have loaded your first custom font! But this is where the task gets a little bit overly complicated, we need to draw with the font. All of the following code is placed in a Code:
- (void)drawRect:(CGRect)rect Code:
// Get the context.
CGContextRef context = UIGraphicsGetCurrentContext();
// Set the customFont to be the font used to draw.
CGContextSetFont(context, customFont);
// Set how the context draws the font, what color, how big.
CGContextSetTextDrawingMode(context, kCGTextFill);
CGContextSetFillColorWithColor(context, self.textColor.CGColor);
CGContextSetFontSize(context, self.font.pointSize);
// Create an array of Glyph's the size of text that will be drawn.
CGGlyph textToPrint[[self.text length]];
// Loop through the entire length of the text.
for (int i = 0; i < textLength; ++i) {
// Store each letter in a Glyph and subtract the MagicNumber to get appropriate value.
textToPrint[i] = [self.text characterAtIndex:i] - 23;
}
From this point all that is needed is to actually draw the text. I would suggest using one of the functions that are for "Drawing Glyphs". If you can't find what these are, search for the CGContext Reference it has them in there. I have left out ALL of the code I have for modifying the spacing when drawing text as I felt it isn't relevant for the time being. Once you get all this working let me know and I will be more then willing to help you out getting the spacing fixed if you have any issues. Best of luck! -Brent |
||
|
|
0
|
|
|
#8 | |
|
Quote:
Like I have a function, and I call the function from a button. How would I call this in the function that the button is using? Like I want to say Hello in a custom font? thanks =D |
||
|
|
0
|
|
|
#9 |
|
Fixed most of my other problems, how do I center the text?
Last edited by Warder; Oct 22, 2008 at 03:49 PM. |
|
|
|
0
|
|
|
#10 |
|
Total noob
Hi im a total noob and need help on using this to load a gurmukhi ttf i have. all i want to do is type text into UITextView on interface builder and let the coding display using the ttf. I really hope this is possible and someone could be nice enough to post some code. I know its a hell of a lot to ask for. but you'd be helping out a lot.
thanks! |
|
|
|
0
|
|
|
#11 |
|
Question...
Hey man, just wondering to the guy who got custom fonts to work:
What kind of member variables would you add if you were to load the font in a UIView class override? Also, where could you find the official font name to call, as I have been loading the font but it seems to create a NIL CGFontRef because the font name that I pass apparently doesnt work. For example, my font name is called Zit Graffiti but the filename is ZITGRAFF.TFF. When I search for it in Spotlight it gives me zit_graffiti. Any of these could be the name I should use, but which one is it? I've been literally trying to get this to work for DAYS and would really appreciate any help frmo anybody who has gotten custom fonts to work in their apps. In most cases I follow the instructions exactly and I cannot get the custom font to appear. |
|
|
|
0
|
|
|
#12 |
|
Just wondering
Does anybody get this done?
__________________
Macbook Pro 2.2G CPU, 2GB RAM, 80GB HD; 16GB iPhone 3G Black. |
|
|
|
0
|
|
|
#13 | |
|
Custom Font
HI Friend , can you share a sample App code for adding custom Font..
Quote:
|
||
|
|
0
|
|
|
#14 |
|
See all that code in the post you quoted? That's it. Spoon-fed to you in tiny digestible chunks. What more can you possibly want?
__________________
Sponsor me to cycle 100Km round London in the dark |
|
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| thread | Thread Starter | Forum | Replies | Last Post |
| Custom Font for Font Swap | St-Jimmy914 | Jailbreaks and iOS Hacks | 2 | Mar 29, 2011 11:42 PM |
| Using Custom Fonts with UIFont Exception | Compile 'em all | iPhone/iPad Programming | 0 | Jan 19, 2009 08:36 PM |
| Custom Fonts? | Jynxxander | OS X | 2 | Dec 13, 2008 04:43 PM |
| Custom fonts | KingYaba | Mac Applications and Mac App Store | 2 | Apr 22, 2008 01:16 PM |
| Using custom fonts in Dreamweaver CSS for Website | mashinhead | Design and Graphics | 3 | Nov 30, 2007 09:22 PM |
All times are GMT -5. The time now is 07:53 PM.







CGRect)rect method.
Linear Mode

