tipo teclado tamaño plus para letra fuente como celular cambiar aumentar aplicacion agrandar iphone objective-c cocoa-touch uiwebview

iphone - teclado - cómo aumentar el tamaño de fuente en UIWebView



letra de iphone (9)

Actualmente no hay una forma expuesta de manipular directamente el DOM en un UIWebView, ni ningún método de conveniencia para manejar cosas como tamaños de fuente. Sugiero archivar Radares .

Una vez dicho esto. puede modificar el tamaño de fuente cambiando el CSS, como cualquier otra página web. Si eso no es posible (usted no controla el contenido), puede escribir una pequeña función de JavaScript para cambiar las propiedades de CSS en las páginas DOM, y ejecutarlo llamando:

- (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script;

cómo aumentar o disminuir el tamaño de fuente de UIWebview, sin usar scalePageToFit: NO;


Tengo 2 botones - A- y A +

@interface NSUInteger textFontSize; - (IBAction)changeTextFontSize:(id)sender { switch ([sender tag]) { case 1: // A- textFontSize = (textFontSize > 50) ? textFontSize -5 : textFontSize; break; case 2: // A+ textFontSize = (textFontSize < 160) ? textFontSize +5 : textFontSize; break; } NSString *jsString = [[NSString alloc] initWithFormat:@"document.getElementsByTagName(''body'')[0].style.webkitTextSizeAdjust= ''%d%%''", textFontSize]; [web stringByEvaluatingJavaScriptFromString:jsString]; [jsString release]; }


Pruebe el siguiente código:

NSString *setTextSizeRule = [NSString stringWithFormat:@"addCSSRule(''body'', ''-webkit-text-size-adjust: %d%%;'')",currentTextSize]; [_webview stringByEvaluatingJavaScriptFromString:setTextSizeRule];


- (void)webViewDidFinishLoad:(UIWebView *)webView { NSString *fontSize=@"143"; NSString *jsString = [[NSString alloc] initWithFormat:@"document.getElementsByTagName(''body'')[0].style.webkitTextSizeAdjust= ''%d%%''",[fontSize intValue]]; [myWebview stringByEvaluatingJavaScriptFromString:jsString]; }


Aquí está el mío para cambiar el tamaño y el color de la fuente en UIWebView:

NSString *myString=@"Hello World!"; int textFontSize=2; NSString *myHTML=[NSString stringWithFormat: @"<html><body><script>var str = ''%@''; document.write(str.fontsize(%d).fontcolor(''green''));</script></body></html>",myString,textFontSize]; [myWebView loadHTMLString:myHTML baseURL:nil];


Prueba este método simple

- (void)webViewDidFinishLoad:(UIWebView *)webView { int fontValue = 150; NSString *webviewFontSize = [NSString stringWithFormat:@"addCSSRule(''body'', ''-webkit-text-size-adjust: %d%%;'')",fontValue]; [your_webview stringByEvaluatingJavaScriptFromString:webviewFontSize]; }


Cambie el tamaño de fuente de los datos HTML obtenidos cambiando la aparición del tamaño de fuente en la cadena html obtenida al tamaño de fuente requerido (40 en este ejemplo) en un método.

strHtml = [self htmlEntityDecode:strHtml];//parsing the html string -(NSString *)htmlEntityDecode:(NSString *)string { string = [string stringByReplacingOccurrencesOfString:@"14px;" withString:@"40"]; string = [string stringByReplacingOccurrencesOfString:@"15px;" withString:@"40"]; string = [string stringByReplacingOccurrencesOfString:@"16px;" withString:@"40"]; string = [string stringByReplacingOccurrencesOfString:@"17px;" withString:@"40"]; string = [string stringByReplacingOccurrencesOfString:@"18px;" withString:@"40"]; string = [string stringByReplacingOccurrencesOfString:@"19px;" withString:@"40"]; string = [string stringByReplacingOccurrencesOfString:@"20px;" withString:@"40"]; return string; }

Entonces, la cadena html: span style = ''font-size: 20px; Se convierte en: span style = ''font-size: 40

Nota: Cambie las otras instancias como gt ;, apos; también para cargar la cadena deseada en su vista web.


en mi caso estoy usando un UISlider para el fontSize, puede ser cualquier valor flotante

func webViewDidFinishLoad(_ webView: UIWebView) { if let fontSize: Float = (self.fontSizeSlider?.value) { webView.stringByEvaluatingJavaScript(from: "document.getElementsByTagName(''body'')[0].style.webkitTextSizeAdjust= ''/(fontSize)%%''") print(fontSize) } }


Swift 3

public func webViewDidFinishLoad(_ webView: UIWebView) { let textSize: Int = 300 webView.stringByEvaluatingJavaScript(from: "document.getElementsByTagName(''body'')[0].style.webkitTextSizeAdjust= ''/(textSize)%%''") }

Mayores Swift :

func webViewDidFinishLoad(webView: UIWebView) { let textSize: Int = 300 webView.stringByEvaluatingJavaScriptFromString("document.getElementsByTagName(''body'')[0].style.webkitTextSizeAdjust= ''/(textSize)%%''") }