FaXianDetailViewController.m 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // FaXianDetailViewController.m
  3. // jitao
  4. //
  5. // Created by 罗云飞 on 2018/9/14.
  6. // Copyright © 2018年 罗云飞. All rights reserved.
  7. //
  8. #import "FaXianDetailViewController.h"
  9. #import <WebKit/WebKit.h>
  10. @interface FaXianDetailViewController ()<UIWebViewDelegate>
  11. @property (nonatomic, strong) UIWebView *webView;
  12. @end
  13. @implementation FaXianDetailViewController
  14. - (void)viewDidLoad {
  15. [super viewDidLoad];
  16. [self setNavTitle:[NSString stringWithFormat:@"%@详情",self.type]];
  17. [self loadUI];
  18. // Do any additional setup after loading the view.
  19. }
  20. - (void)loadUI{
  21. NSMutableString *string = [NSMutableString stringWithString:self.neirong];
  22. NSString *haha = [NSString stringWithFormat:@"<h4 style='text-align:center;font-size:20px'>%@</h4><p style='text-align:right'>%@</p >",self.title,self.time];
  23. [string insertString:haha atIndex:0];
  24. NSString *strUrl = [string stringByReplacingOccurrencesOfString:@"//statics" withString:@"http://statics"];//替换字符
  25. NSString *htmlString = [NSString stringWithFormat:@"<html> \n"
  26. "<head> \n"
  27. "<style type=\"text/css\"> \n"
  28. "body {font-size:15px;}\n"
  29. "</style> \n"
  30. "</head> \n"
  31. "<body>"
  32. "<script type='text/javascript'>"
  33. "window.onload = function(){\n"
  34. "var $img = document.getElementsByTagName('img');\n"
  35. "for(var p in $img){\n"
  36. " $img[p].style.width = '100%%';\n"
  37. "$img[p].style.height ='auto'\n"
  38. "}\n"
  39. "}"
  40. "</script>%@"
  41. "</body>"
  42. "</html>", strUrl];
  43. NSLog(@"===== %@",htmlString);
  44. self.webView = [[UIWebView alloc] init];
  45. // [self.webView setScalesPageToFit:YES];
  46. self.webView.frame = CGRectMake(0, NavHeader, SCREEN_WIDTH, SCREEN_HEIGHT-NavHeader);
  47. self.webView.delegate = self;
  48. [self.webView loadHTMLString:htmlString baseURL:nil];
  49. //添加到view中
  50. [self.view addSubview:self.webView];
  51. }
  52. - (void)webViewDidFinishLoad:(UIWebView *)webView //网页加载完成的时候调用
  53. {
  54. //HTML5的高度
  55. // CGFloat htmlheight = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"] floatValue];
  56. // self.webView.frame = CGRectMake(0, ViewStartY, SCREEN_WIDTH, htmlheight);
  57. }
  58. - (void)didReceiveMemoryWarning {
  59. [super didReceiveMemoryWarning];
  60. // Dispose of any resources that can be recreated.
  61. }
  62. /*
  63. #pragma mark - Navigation
  64. // In a storyboard-based application, you will often want to do a little preparation before navigation
  65. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  66. // Get the new view controller using [segue destinationViewController].
  67. // Pass the selected object to the new view controller.
  68. }
  69. */
  70. @end