2012-12-14 38 views
4

我已經實現了提要解析&以字符串形式獲取內容。現在,我正在通過它編寫html文件。在Web視圖中加載該HTML。我的網絡視圖是表格視圖單元格中的子視圖。更改Iphone SDK中Web視圖的字體大小

enter image description here

,但現在我想改變的Web視圖內容的字體大小,這樣用戶就可以看到一些細節。

我對HTML生成代碼:

NSString * postHTML=[[_parseResults objectAtIndex:indexPath.row]valueForKey:@"summary"]; 

NSString *close =[NSString stringWithFormat:@"</body></html>"]; 

    NSString *HTMLString = [NSString stringWithFormat:@"%@%@", postHTML,close]; 

    [Web_view loadHTMLString:HTMLString baseURL:nil]; 

[cell.contentView addSubview:Web_view]; 

return cell; 

如何更改的Web視圖內容的字體大小?

+0

http://stackoverflow.com/questions/6324548/how-to-change-font-size-in-html-string –

回答

9
[myWeb loadHTMLString:[NSString stringWithFormat:@"<div style='text-align:justify; font-size:45px;font-family:HelveticaNeue-CondensedBold;color:#0000;'>%@%@",postHTML,close] baseURL:nil]; 

你可以設置字體大小字體大小:大小的代碼。

試試這個..我知道它工作與否!

+0

它不能正常工作 –

1

集你的HTML

NSString *string = [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:17], 
         @"<p><i>My data</p>"]; 
+0

什麼是myweb?如果它是網絡視圖,我嘗試這個,但得到錯誤,因爲Web視圖找不到字體方法。 – user1673099

4

在UIWebView中,您可以在傳遞數據時使用所有HTML標記。

[WebView loadHTMLString:[NSString stringWithFormat:@"<div style='text-align:justify; font-size:44px;font-family:HelveticaNeue-CondensedBold;color:#ffff;'>%@",Data] baseURL:nil]; 

使用上面的代碼,其中「數據」將成爲您的內容。

謝謝,

Hemang。