uiappfonts ttf otf font custom ios uiwebview fonts true-type-fonts

ios - ttf - uiappfonts



Usar fuente personalizada en UIWebView (2)

Me gustaría mostrar una fuente personalizada dentro de UIWebView. Ya coloqué la fuente en el plist debajo de "Fuentes provistas por la aplicación". El código en uso:

UIWebView *webView = [[UIWebView alloc] initWithFrame:myRect]; NSURL *baseURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]; [webView loadHTMLString:html baseURL:baseURL]; [self addSubview:webView];

donde html es un NSString que tiene los siguientes contenidos:

<html><head> <style type="text/css"> @font-face { font-family: gotham_symbol; src: local(''GOTHAMboldSymbol_0.tff''), format(''truetype'') } body { font-family: gotham_symbol; font-size: 50pt; } </style> </head><body leftmargin="0" topmargin="0"> This is <i>italic</i> and this is <b>bold</b> and this is some unicode: &#1101; </body></html>

Estoy usando iOS 4.2 para que TTF sea compatible. Apreciaría un poco de html / code que realmente funciona.


Después de algunos intentos y errores, he encontrado una forma confiable de cargar fuentes personalizadas con un CSS local.

1. Agregue su fuente a la aplicación ... asegúrese de que el archivo esté dirigido correctamente a la aplicación

2. Luego agregue su Fuente a su Info-Aplicación.

3. Ejecute NSLog(@"Available fonts: %@", [UIFont familyNames]); Para verificar qué nombre tiene el font / fontfamily para el Sistema ...

4. Copia ese nombre y úsalo en tu CSS ... @ font-face no es necesario

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


Terminé haciéndolo funcionar aunque no estoy seguro de lo que hice mal arriba. Aquí está el HTML que uso (NSString * htmll). Agregué todo, algunos de ellos podrían no ser relevantes para la solución.

<html><head><style type="text/css"> @font-face { font-family: ''gotham_symbol''; src: url(''GOTHAMboldSymbols_0.ttf'') format(''truetype'') } @font-face { font-family: ''gotham_symbol_italic''; src: url(''GothamBoldItalic.ttf'') format(''truetype'') } #w {display:table;} #c {display:table-cell; vertical-align:middle;} i { font-family: ''Helvetica-BoldOblique''; } </style></head><body topmargin="0" leftmargin="0"> <div style="display: table; width: 320px; height: 50px; #position: relative; overflow: hidden;"> <div style=" #position: absolute; #top: 50%;display: table-cell; vertical-align: middle;"> <div style=" #position: relative; #top: -50%"> <p style="font-size:20px;font-family:''gotham_symbol'';color:#97371f;">THE TEXT GOES HERE</p></div></div></div></body></html>

y cargo UIWebView de la siguiente manera:

UIWebView *webView = [[UIWebView alloc] initWithFrame:rect]; [webView makeTransparent]; NSURL *baseURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]; [webView loadHTMLString:html baseURL:baseURL];