Using Custom Font in a Uiwebview

Using custom font in a UIWebView

After some Try and Error I have found a reliable way to load custom Fonts with a local CSS.

1. Add your Font to the App...make sure that the file is targeted
properly to the Application

Sample Image
Sample Image

2. Then add your Font to yourApp-Info.plist

Sample Image

3. Run NSLog(@"Available fonts: %@", [UIFont familyNames]); To check which name the font/fontfamily has for the System...

Sample Image

4. Copy that name and use them in your CSS...@font-face is not needed

body {
font-family:"Liberation Serif";
}

Using a UIWebView, can I use a custom font?

It is possible to load custom fonts into your UIWebView in iOS3.2 and above. Add the font to your bundle (see here) then just reference the font in your UIWebView's stylesheet like you would any other font:

<style type='text/css'>font { font-family: DroidSerif; } </style>

How to include custom font in UIWebview?

Here is what you can do:

let string = "<font face='font-name' size='2'>" + "Your String"

and load webview from this string.

iOS custom font path for UIWebViews

First of all, add filed "Fonts provided by application" in your info.plist. It will be an array like

item0 myFont.otf
item1 anotherFont.ttf

or something.

In HTML use font-face to add a font. And place your font files in the same directory with html file. If HTML is generated dynamically and not shown from bundle then you should copy font .

Good luck.

How to include custom font in UIWebview?

Here is what you can do:

let string = "<font face='font-name' size='2'>" + "Your String"

and load webview from this string.



Related Topics



Leave a reply



Submit