我想减少 HTML 字符串中的空间。下面是正在使用的代码
NSString *headerString = @"<header><meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no'></header>";
headerString = [headerString stringByAppendingString:htmlstring];
headerString = [headerString stringByReplacingOccurrencesOfString:@"<br><br/><br/><br><br/><br/>" withString:@"<br><br/>"];
headerString = [headerString stringByReplacingOccurrencesOfString:@"<br><br/><br><br/>" withString:@"<br><br/>"];
[webviewkit loadHTMLString:headerString baseURL:nil];
我也尝试过使用 Javascript,但我不确定我应该传递的 java 脚本到底是什么,它只会给出 1 行间距而不是多行间距:
- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
[webView evaluateJavaScript:@"document.open();document.close()" completionHandler:^(id _Nullable stringresult, NSError * _Nullable error) {
NSLog(@"result=>%@ error->%@",stringresult,error);
}];
}
但我无法正确删除间距。
<header><meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no'></header><div><span style="font-size: 16px;"><span style="font-size: 16px; font-family: Arial;">Hello and welcome to XYZ session! </span><br><br/><span style="font-family: Arial;">Over the next three Hello world. Spacing takes alot of spaces over here due to span , br and div tags.</span><br><br/><span style="font-family: Arial;">Thank you again for agreeing to participate and helping the discussion....</span><br><br/><span style="font-family: Arial;">Over here,</span><br><br/></span></div><br/><ul><br/> <li><span style="font-size: 16px;"><span style="font-family: Arial;">I will be posting questions over here in stack overflow </span><br><br/> </span></li><br/> <li><span style="font-size: 16px;"><span style="font-family: Arial;">Throughout the day I will read everyone's responses and sometimes respond with my own follow-up questions. </span><br><br/> </span></li><br/> <li><span style="font-size: 16px;"><span style="font-family: Arial;">Please be i request to provide the code in objective c</span><br><br/> </span></li><br/> <li><span style="font-size: 16px;"><span style="font-family: Arial;">Lorem Ipsum is simply dummy text of the printing and typesetting industry. </span><br><br/> </span></li><br/> <li><span style="font-size: 16px;"><span style="font-family: Arial;">Lorem Ipsum is simply dummy text of the printing and typesetting industry. </span><br><br/> </span></li><br/> <li><span style="font-size: 16px; font-family: Arial;">Lorem Ipsum is simply dummy text of the printing and typesetting industry. </span></li><br/></ul>