So I am using a HTML template to style the HTML I get from an API and Im using custom fonts which I get via a file path.
Similar to this Question on here
Or in my case:
/* Body */
@font-face {
font-family: "CustomBodyFontNameHere";
src: url("%@");
}
%@ gets replaced by the file path to my font which I get like this:
NSString *fontPath1 = [[NSBundle mainBundle] URLForResource:@"fontName" withExtension:@".ttf"]
The font file path will be something like this: file:///Users/Ash/Library/Developer/CoreSimulator/Devices/42D419EE-8B2D-4840-B0C7-9DE4091E6AF7/data/Containers/Bundle/Application/24C6D03C-6F62-44D4-BE89-32CC60D4F186/AppName.app/fontName.ttf
And the base URL I'm using is similar to this: http://myWebsite.com/
However the custom font never displays when I'm using a base URL, I have to use a base url so the images in the HTML from the API are displayed. Just to confirm again the base url points to an actual website and not to the main build on the device.
If I set my base URL to nil, my custom font is displayed correctly in the UIWebView e.g:
webContentView?.loadHTMLString(injectedString, baseURL: nil)
So my custom fonts are installed correctly.
From what I can tell the issue is that the baseURL is stopping the UIWebView from correctly loading my font via the file path url.
Is there a way for me to be able to load my custom fonts via the main bundle file path and at the same time use a remote base URL?