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
2. Then add your Font to yourApp-Info.plist
3. Run NSLog(@"Available fonts: %@", [UIFont familyNames]);
To check which name the font/fontfamily has for the System...
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
Ios: Frame.Size.Width/2 Doesn't Produce a Circle on Every Device
Send Messages Between iOS and Watchos with Watchconnectivity in Watchos2
How to Present a Uiviewcontroller from Skscene
iOS 7 Uiwebview Keyboard Issue
How to Debug "Terminated Due to Memory Error"
Color All Occurrences of String in Swift
iOS 13.1 Crash in Avaudio Player
What Is Sandbox in iOS? How to Transfer Data Between One App to Another App
Resize Textfield Based on Content
Nsdateformatter Milliseconds Bug
How to Force a Hkquery to Load the Most Recent Steps Counts
Create a Copy of a Uiview in Swift
How to Use Core Location/Gps Without Any Internet Connection/Disabled Cellular Network
How to Lookup a String Constant at Runtime in Objective-C