【问题标题】:Display HTML content in UIView Objective C在 UIView Objective C 中显示 HTML 内容
【发布时间】:2017-11-20 06:14:14
【问题描述】:

我在 UIView 中显示 HTML 内容时遇到问题。 以下是我来自服务的 HTML 响应

EmpTable = "<table width='600' border='0' cellspacing='1' cellpadding='8' bgcolor='#d4d4d4'><tr><th>Employee</th><th>Designation</th><th>Date</th><th>Time</th></tr><tr><td>Work Place</td><td>Emp Join Date</td><td>10-09-2009</td><td>17:06</td></tr><tr><td>Emp Attendance</td><td>Emp Id</td><td>11-09-2017</td><td>17:05</td></tr><tr><td>Employee</td><td>Employee Name</td><td>11-09-2017</td><td>09:04</td></tr><tr><td colspan='4' align='RIGHT'><span style='font-family: Verdana; font-size: xx-small;'><strong><span style='color: red;'>*</span>\U00a0- 24 Hrs Format<br /><br /></strong></span></td></tr></table>";

不知道如何在 UIView 中显示相同的 HTML 响应。请寻求一些帮助来解决这个问题。TIA

【问题讨论】:

  • 听说过 webView ??这就是你不需要 UIView 的全部
  • @Rajeev 使用 Web 视图显示 HTML 内容
  • 我相信使用 WebView 将解决您的问题。 @Rajeev

标签: ios objective-c iphone json xcode


【解决方案1】:

你可以使用Webview,也可以试试UITextView。

NSAttributedString * str = [[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil];

textview.attributedText = str;

【讨论】:

    【解决方案2】:

    您应该使用WKWebView 而不是UIView。下面是如何使用WKWebView的简单示例。

    WKWebView *webView = [[WKWebView alloc] initWithFrame:self.view.frame]; // change frame that you need 
    webView.navigationDelegate = self;
    NSURL *nsurl=[NSURL URLWithString:@"http://www.apple.com"];
    NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl]; // you can set here HTML content too.      
    [webView loadRequest:nsrequest];
    [self.view addSubview:webView];
    

    更多信息可以阅读this tutorial.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-13
      • 1970-01-01
      • 2016-04-27
      • 1970-01-01
      • 2014-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多