sirve salud que pasos para mide los hack funciona fisica como app actividad iphone uiwebview

salud - Desarrollo de iPhone-Configuración de la fuente UIWebView



uiwebview facebook hack (9)

Aquí está mi solución fácil de usar y fácil de ampliar con más configuraciones de fuentes:

myHTMLLabel = [[UIWebView alloc] initWithFrame:CGRectMake(myX,myY,myWidth,myHeight)]; myHTMLLabel.userInteractionEnabled=NO; myHTMLLabel.scalesPageToFit=NO; [myHTMLLabel setOpaque:NO]; myHTMLLabel.backgroundColor = myBackColor; NSString *myHTMLText = [NSString stringWithFormat:@"<html>" "<head><style type=''text/css''>" ".main_text {" " display: block;" " font-family:[fontName];" " text-decoration:none;" " font-size:[fontSize]px;" " color:[fontColor];" " line-height: [fontSize]px;" " font-weight:normal;" " text-align:[textAlign];" "}" "</style></head>" "<body> <SPAN class=''main_text''>[text]</SPAN></body></html>"]; myHTMLText = [myHTMLText stringByReplacingOccurrencesOfString: @"[text]" withString: myText]; myHTMLText = [myHTMLText stringByReplacingOccurrencesOfString: @"[fontName]" withString: myFontName]; myHTMLText = [myHTMLText stringByReplacingOccurrencesOfString: @"[fontSize]" withString: myFontSize]; myHTMLText = [myHTMLText stringByReplacingOccurrencesOfString: @"[fontColor]" withString: myFontColorHex]; myHTMLText = [myHTMLText stringByReplacingOccurrencesOfString: @"[textAlign]" withString: myFontAlign]; NSLog(@"*** renderHTMLText --> myHTMLText: %@",myHTMLText); [myHTMLLabel loadHTMLString:myHTMLText baseURL:nil];

Tengo que mostrar el texto enriquecido que saco del servidor, entonces estoy usando UIWebView. Ahora el problema es que no tengo control sobre la fuente que se usa en UIWebView. ¿Cómo puedo cambiar la fuente para usar la fuente del sistema (por lo que es coherente con el resto de la aplicación)?

Estoy haciendo algo como esto en este momento:

myRichTextView = [[UIWebView alloc] initWithFrame:CGRectMake(x, y, width, height)]; myRichTextView.backgroundColor = [UIColor clearColor]; [myRichTextView setScalesPageToFit:NO]; [myRichTextView loadHTMLString:myString baseURL:[NSURL URLWithString:myBaseURL]];

De nuevo, necesita controlar la fuente de visualización. Si no puedo controlar la fuente, hágamelo saber otras alternativas a UIWebView.

Gracias


Fuente del sistema

-apple-system en iOS 9 y Safari OS X 10

font-family: -apple-system; font-family: ''-apple-system'',''HelveticaNeue''; // iOS 8 compatible


Funcionó cuando modifiqué la cadena de esta manera. Tu chris derecho, no debería hacer ninguna diferencia.

NSString *myDescriptionHTML = [NSString stringWithFormat:@"<html> /n" "<head> /n" "<style type=/"text/css/"> /n" "body {font-family: /"%@/"; font-size: %@;}/n" "</style> /n" "</head> /n" "<body>%@</body> /n" "</html>", @"helvetica", [NSNumber numberWithInt:kFieldFontSize], content];


Haga referencia a una hoja de estilo css en su documento HTML o coloque la información de estilo en la parte superior del documento HTML en sí


Uso el siguiente CSS en una vista web para hacer exactamente lo que dices.

body { font-family:helvetica; }

Pero el tuyo parece que debería funcionar también. Extraño. La única diferencia que puedo ver es la fuente versus la familia de fuentes, pero eso no debería marcar la diferencia.

Chris.


otra manera fácil que funcionó para mí

UIFont *font = [UIFont systemFontOfSize:15]; NSString *htmlString = [NSString stringWithFormat:@"<span style=/"font-family:Helvetica; font-size: %i/">%@</span>", (int) font.pointSize, [bodyText stringWithNewLinesAsBRs]]; [myWebView loadHTMLString:htmlString baseURL:nil];


solo cambia

font:helvetica

a

font-family:helvetica


yo suelo

body { font-family: ''Noteworthy-Bold''; }

Esto funciona bien para mi página virtual (WebView), ya que el resto de mi aplicación también usa "Noteworthy-Bold" de Apple.

Si desea usar su propia fuente, use @ font-face y consulte un archivo TTF o EOT.


Hice un método que envuelve un texto en un cuerpo HTML con el estilo correcto para un UIColor y un UIColor UIFont . Está basado en la respuesta de Mustafa .

Se usa así:

NSString * htmlString = [MyClass htmlFromBodyString:@"an <b>example</b>" textFont:[UIFont systemFontOfSize:10] textColor:[UIColor grayColor]]; [webView loadHTMLString:htmlString baseURL:nil];