2014-08-27 95 views
0

嗨,大家好我寫了一個簡單的應用程序,在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> 

回答

0

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

相關問題