我有一个 UIWebView,我有一个自定义字体我想加载到一个可编辑的 html 文档中,我将通过 UIWebView 显示它。在我的 SupportingFiles(资源)文件夹中,我有“Nosifer-Regular.ttf”...要在我的 HTML 中使用自定义字体,我需要字体拼贴的路径(URL)...我尝试这样做,但它没有t似乎工作......有什么想法吗?
bundle = [NSBundle mainBundle];
pathFont = [bundle bundlePath];
fontURL = [NSBundle pathForResource:@"Nosifer-Regular" ofType:@"ttf" inDirectory:pathFont];
path_font = [fontURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
fileAppend = [[NSString alloc] initWithFormat:@"file://"];
path_font = [[NSString alloc] initWithFormat:@"%@%@", fileAppend, path_font];
HTML(CSS):
@font-face {
font-family: 'Nosifer';
font-style: normal;
font-weight: 400;
src: local('Nosifer'), local('Nosifer-Regular'), url('%@') format('truetype');
}
其中 %@ 替换为“path_font”(在上面的第一个代码块中定义)