在如今追求快速高效的今天, 将 iOS与 html 混编已经很流行, 一方面结合了 html 的快速创建,在加上iOS的落实开发, 能将两者结合将是最好的选择.
如下:
//拼接CSS
NSString *string = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"markdown" ofType:@"css"] encoding:NSUTF8StringEncoding error:nil];
NSString *newContent = [NSString stringWithFormat:@"<style type=\"text/css\">%@</style>", string];
NSString *endStr = [NSString stringWithFormat:@"<html>%@<div class=\"tit\"><h3>%@</h3><div class=\"tl\">%@<span> %@</span><hr/></div></div><body>%@</body><p class=\"author_site\" style=\"text-align:right;\">   (科技资讯)</p><br/></div></html>", newContent,self.title1,[self.endtime substringToIndex:10], self.source, self.text];
//创建webview对象
self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
// self.webView.scalesPageToFit = YES;
[self.webView loadHTMLString:[NSString stringWithFormat:@"<head><style>img{width:%fpx !important;height:%fpx;}</style></head>%@",KDeviceWidth-20,KDeviceWidth-70,endStr] baseURL:nil];
self.webView.scrollView.bounces = NO;//禁止滚动弹跳
UISwipeGestureRecognizer *swipGesture = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeBack)];
swipGesture.direction = UISwipeGestureRecognizerDirectionRight;
[self.webView.scrollView addGestureRecognizer:swipGesture];
[self.view addSubview:self.webView];
iOS与 HTML混编
最新推荐文章于 2024-04-22 11:07:19 发布