TongyongDetailViewController.m 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. //
  2. // TongyongDetailViewController.m
  3. // jitao
  4. //
  5. // Created by 罗云飞 on 2018/8/19.
  6. // Copyright © 2018年 罗云飞. All rights reserved.
  7. //
  8. #import "TongyongDetailViewController.h"
  9. @interface TongyongDetailViewController ()<UIWebViewDelegate>{
  10. UITableView *newtableView;
  11. UIWebView *_myWebView;
  12. }
  13. @end
  14. @implementation TongyongDetailViewController
  15. - (void)viewDidLoad {
  16. [super viewDidLoad];
  17. [self setNavTitle:[NSString stringWithFormat:@"%@详情",self.type]];
  18. [self loadUI];
  19. // Do any additional setup after loading the view.
  20. }
  21. - (void)loadUI{
  22. [self.view addSubview:newtableView = [NewControlPackage tableViewInitWithFrame:CGRectMake(0, NavHeader, SCREEN_WIDTH, SCREEN_HEIGHT) backgroundColor:NewWhiteColor style:1 delegate:self dataSource:self showsHorizontalScrollIndicator:NO showsVerticalScrollIndicator:NO hidden:NO tag:100 userInteractionEnabled:YES]];
  23. newtableView.separatorStyle = NO;
  24. }
  25. #pragma mark-------------------------UITableView------------------------------------
  26. -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  27. {
  28. return 1;
  29. }
  30. //返回每段行数
  31. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  32. {
  33. return 1;
  34. }
  35. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  36. {
  37. static NSString *Cell = @"Cell";
  38. UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:Cell];
  39. if (cell == nil) {
  40. cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell];
  41. }
  42. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//(这种是没有点击后的阴影效果)
  43. cell.accessoryType = UITableViewCellAccessoryNone;
  44. // UILabel *title = [UILabel new];
  45. // title.text = self.title;
  46. // title.font = NewFont(17);
  47. // title.textAlignment = NSTextAlignmentCenter;
  48. // [cell.contentView addSubview:title];
  49. //
  50. // title.sd_layout
  51. // .leftSpaceToView(cell.contentView, 15)
  52. // .topSpaceToView(cell.contentView, 30)
  53. // .rightSpaceToView(cell.contentView, 15)
  54. // .autoHeightRatio(0);
  55. //
  56. // UILabel *time = [UILabel new];
  57. // time.text = self.time;
  58. // time.font = NewFont(15);
  59. // [time setSingleLineAutoResizeWithMaxWidth:0];
  60. // time.textColor = [UIColor colorWithString:@"#6C6C6C"];
  61. // [cell.contentView addSubview:time];
  62. //
  63. // time.sd_layout
  64. // .rightSpaceToView(cell.contentView, 15)
  65. // .heightIs(15)
  66. // .topSpaceToView(title, 20);
  67. _myWebView = [[UIWebView alloc] init];
  68. // [_myWebView.scrollView setDelegate:self];
  69. [_myWebView setDelegate:self];
  70. _myWebView.scrollView.tag = 112;
  71. _myWebView.backgroundColor = [UIColor clearColor];
  72. //自动对页面进行缩放以适应屏幕
  73. // [_myWebView setScalesPageToFit:YES];
  74. [cell.contentView addSubview:_myWebView];
  75. _myWebView.sd_layout
  76. .leftSpaceToView(cell.contentView, 0)
  77. .rightSpaceToView(cell.contentView, 0)
  78. .bottomSpaceToView(cell.contentView, 0)
  79. .topSpaceToView(cell.contentView, 0);
  80. if (self.neirong.length>0) {
  81. NSMutableString *string = [NSMutableString stringWithString:self.neirong];
  82. [string insertString:@"<h4 style='text-align:center;font-size:20px'>标题</h4><p style='text-align:right'>2018-10-12</p >" atIndex:0];
  83. NSString *strUrl = [string stringByReplacingOccurrencesOfString:@"//statics" withString:@"http://statics"];//替换字符
  84. // NSString *fffff = [strUrl stringByReplacingOccurrencesOfString:@"<img" withString:@"< img style=\"width:100%\" "];//替换字符
  85. NSString *htmlString = [NSString stringWithFormat:@"<html> \n"
  86. "<head> \n"
  87. "<style type=\"text/css\"> \n"
  88. "body {font-size:15px;}\n"
  89. "</style> \n"
  90. "</head> \n"
  91. "<body>"
  92. "<script type='text/javascript'>"
  93. "window.onload = function(){\n"
  94. "var $img = document.getElementsByTagName('img');\n"
  95. "for(var p in $img){\n"
  96. " $img[p].style.width = '100%%';\n"
  97. "$img[p].style.height ='auto'\n"
  98. "}\n"
  99. "}"
  100. "</script>%@"
  101. "</body>"
  102. "</html>", strUrl];
  103. NSLog(@"===== %@",htmlString);
  104. [_myWebView loadHTMLString:htmlString baseURL:nil];
  105. }
  106. return cell;
  107. }
  108. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
  109. {
  110. CGFloat width = [NewUtils heightforString:self.neirong andWidth:SCREEN_WIDTH-30 fontSize:16];
  111. return SCREEN_HEIGHT+width;
  112. }
  113. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
  114. }
  115. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
  116. return CGFLOAT_MIN;
  117. }
  118. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
  119. return CGFLOAT_MIN;
  120. }
  121. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  122. return [[UIView alloc] init];
  123. }
  124. - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
  125. return [[UIView alloc] init];
  126. }
  127. - (void)didReceiveMemoryWarning {
  128. [super didReceiveMemoryWarning];
  129. // Dispose of any resources that can be recreated.
  130. }
  131. /*
  132. #pragma mark - Navigation
  133. // In a storyboard-based application, you will often want to do a little preparation before navigation
  134. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  135. // Get the new view controller using [segue destinationViewController].
  136. // Pass the selected object to the new view controller.
  137. }
  138. */
  139. @end