更改按一个按钮的HTML字体大小

更改按一个按钮的HTML字体大小

问题描述:

嗨,大家好我写了一个简单的应用程序,在web视图中显示一个html文件,该html文件在主包中。 我不知道我怎样才能使HTML文件字体大小大/小由两个按钮 这是我的.m更改按一个按钮的HTML字体大小

#import "ViewController.h" 

@interface ViewController() 

@end 

@implementation ViewController 
@synthesize webView; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 

    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"jama" ofType:@"htm"]isDirectory:NO]]]; 


} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

- (IBAction)increase:(id)sender { 

    } 

- (IBAction)decrease:(id)sender { 

    } 


@end 

,这是我的HTML文件,该文件是在我的主束

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
    <meta http-equiv="Content-Style-Type" content="text/css"> 
    <title></title> 
    <meta name="Generator" content="Cocoa HTML Writer"> 
    <meta name="CocoaVersion" content="1265.21"> 
    <style type="text/css"> 
    p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; text-align: left; font: 21.0px 'Geeza Pro'} 
    </style> 
</head> 
<body> 
<p dir="rtl" class="p1"><b> hello </b></p> 
</body> 
</html> 

UIWebview有一种方法,可以使用stringByEvaluatingJavaScriptFromString在当前站点的DOM内部执行JavaScript命令。

用下面的方法调用一个简单的JavaScript命令,例如:

// your javascript command that will alter the layout og your html 
NSString *javascript = @"document.getElementById('myP').style.fontSize='large';"; 

// tell the webview to execute a script on your current page. this method must be called once the page has completely loaded. 
[webView stringByEvaluatingJavaScriptFromString:javascript]; 

注意:你需要知道的基本JavaScript和HTML,以了解命令的工作作为你与互动与网页内容。

+0

也许是因为我刚刚接触编程,我不明白,请你简化答案 – ALz 2014-08-27 17:09:31