Custom Fonts

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Custom Fonts

Anita H.
Hi,

Has anyone had any luck embedding custom fonts in their apps? I can't seem to get it to work! I've added an "Application fonts resource path" key to my info.plist file, with the path to my font folder. I've also tried adding the UIAppFonts array key to the info.plist file, and added an item with a path to my font. I've added my font to my monotouch project, and tried setting the build action to both Content and Embed as Resource. Still, no matter what I do, when I call UIFont.FromName with my font name, it returns null.

Any help would be much appreciated!!

Thanks!
Anita Hirth
Creative and Technical Director
Smart Cookie Studios
Website   Twitter   Facebook   Blog
Reply | Threaded
Open this post in threaded view
|

Re: Custom Fonts

David Moles
Works for me. Try having your app dump out all the installed font names -- the name of yours might not be what you expect.

On Sat, Jun 11, 2011 at 6:06 PM, bluuemango <[hidden email]> wrote:
Hi,

Has anyone had any luck embedding custom fonts in their apps? I can't seem
to get it to work! I've added an "Application fonts resource path" key to my
info.plist file, with the path to my font folder. I've also tried adding the
UIAppFonts array key to the info.plist file, and added an item with a path
to my font. I've added my font to my monotouch project, and tried setting
the build action to both Content and Embed as Resource. Still, no matter
what I do, when I call UIFont.FromName with my font name, it returns null.

Any help would be much appreciated!!

Thanks!

--
View this message in context: http://monotouch.2284126.n4.nabble.com/Custom-Fonts-tp3591283p3591283.html
Sent from the MonoTouch mailing list archive at Nabble.com.
_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch



--
David Moles

_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch
Reply | Threaded
Open this post in threaded view
|

Re: Custom Fonts

Anita H.
How do I view installed fonts? I don't have access to the System.Drawing.Text.InstalledFontCollection class.

Thanks!
Anita Hirth
Creative and Technical Director
Smart Cookie Studios
Website   Twitter   Facebook   Blog
Reply | Threaded
Open this post in threaded view
|

Re: Custom Fonts

David Moles
You need to use the native API (Monotouch.UIKit.UIFont). Put this in your FinishedLaunching to dump a list of all the fonts to the console:

String fonts = "--------------------------------------\n";
List<String> fontFamilies = new List<String> (UIFont.FamilyNames);
fontFamilies.Sort ();
foreach (String familyName in fontFamilies) {
foreach (String fontName in UIFont.FontNamesForFamilyName (familyName)) {
fonts += familyName;
fonts += "\t";
fonts += fontName;
fonts += "\n";
}
fonts += "--------------------------------------\n";
}
Console.WriteLine (fonts);


On Sat, Jun 11, 2011 at 6:25 PM, bluuemango <[hidden email]> wrote:
How do I view installed fonts? I don't have access to the
System.Drawing.Text.InstalledFontCollection class.

Thanks!


--
View this message in context: http://monotouch.2284126.n4.nabble.com/Custom-Fonts-tp3591283p3591313.html
Sent from the MonoTouch mailing list archive at Nabble.com.
_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch



--
David Moles

_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch
Reply | Threaded
Open this post in threaded view
|

Re: Custom Fonts

Anita H.
Hi David,

I have a few questions about the settings you used to get this to work:

Which key did you add to the info.plist file - "Application fonts resource path" or "UIAppFonts"?

For the value of the key, did you give the folder where the tff file resides, or the full path to the ttf file?

When adding the ttf file to your project, did you set the build action to Content or Embed as Resource?

Your help is very much appreciated!

Thanks,
Anita
Anita Hirth
Creative and Technical Director
Smart Cookie Studios
Website   Twitter   Facebook   Blog
Reply | Threaded
Open this post in threaded view
|

Re: Custom Fonts

David Moles
UIAppFonts. The relevant section of the Info.plist file looks like:

<key>UIAppFonts</key>
<array>
<string>Fonts/Chunk.otf</string>
<string>Fonts/lmmono10-regular.otf</string>
<string>Fonts/lmmono10-italic.otf</string>
<string>Fonts/lmmonocaps10-regular.otf</string>
<string>Fonts/lmmonocaps10-oblique.otf</string>
</array>

"Fonts" is a subdirectory of the project root (i.e., at the same level as Main.cs and Info.plist) and the build action for the font files is "Content." I'm not sure what "Resource" is for but it doesn't seem to be much use with MonoTouch. :) 

--D.

On Mon, Jun 13, 2011 at 7:47 AM, bluuemango <[hidden email]> wrote:
Hi David,

I have a few questions about the settings you used to get this to work:

Which key did you add to the info.plist file - "Application fonts resource
path" or "UIAppFonts"?

For the value of the key, did you give the folder where the tff file
resides, or the full path to the ttf file?

When adding the ttf file to your project, did you set the build action to
Content or Embed as Resource?

Your help is very much appreciated!

Thanks,
Anita

--
View this message in context: http://monotouch.2284126.n4.nabble.com/Custom-Fonts-tp3591283p3593997.html
Sent from the MonoTouch mailing list archive at Nabble.com.
_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch



--
David Moles

_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch
Reply | Threaded
Open this post in threaded view
|

Re: Custom Fonts

Anita H.
Thanks so much, that worked!!
Anita Hirth
Creative and Technical Director
Smart Cookie Studios
Website   Twitter   Facebook   Blog
Reply | Threaded
Open this post in threaded view
|

Re: Custom Fonts

David Moles
No problem.

On Mon, Jun 13, 2011 at 7:11 PM, bluuemango <[hidden email]> wrote:
Thanks so much, that worked!!

--
View this message in context: http://monotouch.2284126.n4.nabble.com/Custom-Fonts-tp3591283p3595502.html
Sent from the MonoTouch mailing list archive at Nabble.com.
_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch



--
David Moles

_______________________________________________
MonoTouch mailing list
[hidden email]
http://lists.ximian.com/mailman/listinfo/monotouch