Change font size for web view in Iphone SDK

牧云@^-^@ 提交于 2019-12-10 17:28:46

问题


I have implementing feed parsing & get the content as a string. Now, I am making html file through it programetically. Load that HTML in the Web view. My web View is the subview in Table View cell.

But Now i want to change the font size of web view content, so the user can see some detail .

My code for HTML generation is:

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;

How can i change font size of web view content??


回答1:


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

you can set font size in font-size:size in code.

try this..let me know it is working or not!!!




回答2:


In UIWebView, you can use all HTML Tags while passing the data.

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

Use above code where "Data" will be your content.

Thanks,

Hemang.




回答3:


set in your 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>"];


来源:https://stackoverflow.com/questions/13877470/change-font-size-for-web-view-in-iphone-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!