Xcode创建一个本地的Html

来源:互联网 发布:芙蓉云计算数据朱震风 编辑:程序博客网 时间:2024/04/30 13:33

怎样自己创建一个本地的Html


1创建文件



2.在里面写

<html>

<head lang="en">

<meta charset="UTF-8">

<title></title>

<style>

img{

width: 100%;

}

</style>

</head>

<body>

</body>

</html>


3.调用

cell中


- (void)awakeFromNib{

   self.webView.delegate =self;

    self.webView.userInteractionEnabled =NO;

}


- (void)setWebContent:(NSString *)webContent{

   _webContent = webContent;

    if (_webContent) {

        [self.webViewloadHTMLString:[selfaddCssWithContent:_webContent]baseURL:nil];

    }

}


- (void)webViewDidFinishLoad:(UIWebView *)webView {

   if (!loaded) {

        NSString *height_str= [webViewstringByEvaluatingJavaScriptFromString: @"document.body.offsetHeight"];

       CGFloat height = [height_str floatValue];

        if (self.webLoadDoneBlock) {

           self.webLoadDoneBlock(height);

        }

       loaded = YES;

    }

}


- (NSString *)addCssWithContent:(NSString*)content {

    NSMutableString *htmlText = [NSMutableStringstringWithContentsOfFile:[[NSBundlemainBundle] pathForResource:@"htmlText"ofType:nil]encoding:NSUTF8StringEncodingerror:nil];

    [htmlTextinsertString:content atIndex:htmlText.length-15];

   return htmlText;

}


ViewController中

 ProdDetailWebCell *cell = [tableViewdequeueReusableCellWithIdentifier:@"ProdDetailWebCell"];

            cell.webContent =_webContent;

            cell.webLoadDoneBlock = ^(CGFloat height){

               _webHeight = height;

                [tableViewreloadData];

            };

           return cell;




0 0
原创粉丝点击