| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- //
- // FaXianDetailViewController.m
- // jitao
- //
- // Created by 罗云飞 on 2018/9/14.
- // Copyright © 2018年 罗云飞. All rights reserved.
- //
- #import "FaXianDetailViewController.h"
- #import <WebKit/WebKit.h>
- @interface FaXianDetailViewController ()<UIWebViewDelegate>
- @property (nonatomic, strong) UIWebView *webView;
- @end
- @implementation FaXianDetailViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self setNavTitle:[NSString stringWithFormat:@"%@详情",self.type]];
- [self loadUI];
- // Do any additional setup after loading the view.
- }
- - (void)loadUI{
- NSMutableString *string = [NSMutableString stringWithString:self.neirong];
- NSString *haha = [NSString stringWithFormat:@"<h4 style='text-align:center;font-size:20px'>%@</h4><p style='text-align:right'>%@</p >",self.title,self.time];
- [string insertString:haha atIndex:0];
- NSString *strUrl = [string stringByReplacingOccurrencesOfString:@"//statics" withString:@"http://statics"];//替换字符
- NSString *htmlString = [NSString stringWithFormat:@"<html> \n"
- "<head> \n"
- "<style type=\"text/css\"> \n"
- "body {font-size:15px;}\n"
- "</style> \n"
- "</head> \n"
- "<body>"
- "<script type='text/javascript'>"
- "window.onload = function(){\n"
- "var $img = document.getElementsByTagName('img');\n"
- "for(var p in $img){\n"
- " $img[p].style.width = '100%%';\n"
- "$img[p].style.height ='auto'\n"
- "}\n"
- "}"
- "</script>%@"
- "</body>"
- "</html>", strUrl];
-
- NSLog(@"===== %@",htmlString);
-
-
- self.webView = [[UIWebView alloc] init];
- // [self.webView setScalesPageToFit:YES];
- self.webView.frame = CGRectMake(0, NavHeader, SCREEN_WIDTH, SCREEN_HEIGHT-NavHeader);
- self.webView.delegate = self;
- [self.webView loadHTMLString:htmlString baseURL:nil];
- //添加到view中
- [self.view addSubview:self.webView];
-
- }
- - (void)webViewDidFinishLoad:(UIWebView *)webView //网页加载完成的时候调用
- {
- //HTML5的高度
- // CGFloat htmlheight = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"] floatValue];
- // self.webView.frame = CGRectMake(0, ViewStartY, SCREEN_WIDTH, htmlheight);
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|