【问题标题】:How to show a specific part of website on Webview? (Xcode 7 Swift 2)如何在 Webview 上显示网站的特定部分? (Xcode 7 斯威夫特 2)
【发布时间】:2015-11-11 22:30:34
【问题描述】:

我正在尝试从我的学校网站制作一个显示教师目录的应用程序。仅使用 uiwebview 并加载网站的问题在于该网站并未针对移动设备进行优化,因此所有额外的标题和侧面板都会显示。我只想要网站的中间特定部分。我找到了 div 和所有内容,但似乎不能只显示网站的中间内容而不是整个网站。

【问题讨论】:

    标签: html ios xcode uiwebview


    【解决方案1】:

    获取html内容,然后去掉不需要的标签并传递给webview

    NSString *string = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://yourwebsite.com"] encoding:NSASCIIStringEncoding error:nil];
    
       NSLog(@"String is %@",string);
      //String will contain the whole tags. Just strip the content in string which you want and pass it to webview
    
    [self.webview loadHTMLString:string baseURL:nil];
    

    【讨论】:

      猜你喜欢
      • 2017-03-24
      • 1970-01-01
      • 1970-01-01
      • 2017-02-15
      • 1970-01-01
      • 2017-07-22
      • 2017-11-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多