在 iOS 中将 UIWebview 的字体设置为粗体

Make UIWebview's font bold in iOS

如何将字体设置为粗体

[cell.itemContentWebView loadHTMLString:[NSString stringWithFormat:@"<div style='font-family:-apple-system','HelveticaNeue-Bold; style='font-size:24px;'>%@",object.title] baseURL:nil];

拉菲回答你的问题

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
   //Font size
   int fontSize = 80;
   NSString *jsString = [[NSString alloc] initWithFormat:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '%d%%'", fontSize];
  [webview stringByEvaluatingJavaScriptFromString:jsString];
  //Font Family Style - Bold
   NSString *jsWebViewFontFamilyString = [[NSString alloc] initWithFormat:@"document.getElementsByTagName('body')[0].style.fontFamily = 'HelveticaNeue-Bold'"];
  [webview stringByEvaluatingJavaScriptFromString:jsWebViewFontFamilyString];
  //Font Color or web view text color
  [webview stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.color = 'Green'"]; 

}

在加载到 webView 之前,只需在您的字符串前添加一个标签。

NSString *body = [plist objectForKey:@"foo"];
NSString *htmlString = 
    [NSString stringWithFormat:@"<font face='GothamRounded-Bold' size='3'>%@", body];
[webView loadHTMLString:htmlString baseURL:nil];