我正在将字符串中以 px 为单位的字体替换为另一个值。之后,我替换了字符串中的 px,我将它传递给 UIWebView 以显示它。问题是我更改了px值后,没有效果。
该字符串包含这样的 HTML(例如):
<html><head><script> document.ontouchmove = function(event) { if (document.body.scrollHeight == document.body.clientHeight) event.preventDefault(); } </script><style type='text/css'>* { margin:0; padding:0; } p { color:black; font-family:Helvetica; font-size:26px; } a { color:#000000;}</style></head><body>Look at Google</body></html>
代码如下所示:
//Setting of WebSites Text
NSString *websitesHTML = [[websitesArray objectAtIndex:index] objectForKey:@"Websites"];
//For iPad
NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\\d\\dpx;" options:NSRegularExpressionCaseInsensitive error:&error];
NSString *modifiedWebsitesHTML = [regex stringByReplacingMatchesInString:websitesHTML options:0 range:NSMakeRange(0, [websitesHTML length]) withTemplate:@"40px"];
NSLog(@"%@",modifiedWebsitesHTML);
UIWebView *websitesWebView = [[UIWebView alloc] init];
[websitesWebView setFrame:CGRectMake(15, 160, 600, 300)];
websitesWebView.delegate = self;
[websitesWebView setOpaque:NO];
websitesWebView.backgroundColor = [UIColor clearColor];
[websitesWebView loadHTMLString:modifiedWebsitesHTML baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
[self.view addSubview:websitesWebView];
任何建议都会有所帮助......需要一些指导......