【问题标题】:how to put text in Webview?如何在 Webview 中放置文本?
【发布时间】:2011-03-24 12:31:38
【问题描述】:

我有这种4段。

像这样:

我今天站在这里,为摆在我们面前的任务感到谦卑,感谢您给予的信任,铭记我们的祖先所承担的牺牲。我感谢布什总统为我们国家所做的服务,以及他在整个过渡期间所表现出的慷慨与合作。

我想使用 webview 在不同的视图中使用这些段落。

我的意思是我想在 UIWebview 中显示这样的段落

谁能告诉我怎么做?

【问题讨论】:

  • 您有网站显示这些段落吗? UIWebview 是用来显示网页内容的。如果你只想呈现静态文本,你应该使用 UITextView。
  • 是的静态文本...但是我不能使用 IB 另外...另外我必须制作一些 html...并且使用它我必须显示这个

标签: iphone ios uiwebview uitextview


【解决方案1】:
[webView1 loadHTMLString:@"Welcome to StackOverFlow" baseURL:nil];  

【讨论】:

    【解决方案2】:
    [myWebView loadHTMLString:@"<p>I stand here today humbled by the task before us, grateful for the trust you have bestowed, mindful of the sacrifices borne by our ancestors. I thank President Bush for his service to our nation, as well as the generosity and cooperation he has shown throughout this transition</p>"]
    

    【讨论】:

      【解决方案3】:

      如果你真的必须在 UIWebview 中显示文本,请实现一个实现 UIWebView 委托协议的类,如下所示:

      @interface Web : UIViewController <UIWebViewDelegate> {
          UIWebView *webView;
          NSString *uRLString;
      
      }
      
      @property (nonatomic, retain) IBOutlet UIWebView *webView;
      @property (nonatomic, retain) NSString *uRLString;
      

      在您的 .m 文件中,您可以像这样在 viewDidLoad 中设置委托和视图:

      self.view = webView.view;
      self.webView.delegate = self;
      

      并像这样实现 openURL:

      - (void)openURL:(NSString *)urlString
      {
      [myWebView loadHTMLString: <your static string in html-formate>]
      
      }
      

      但就像我之前说的:您应该使用 UITextView 来遵守 Apple 准则,并且您也可以在没有 IB 的情况下设置 UITextView 的首选项。事实上,你真的永远不必使用 IB。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-06-10
        • 1970-01-01
        • 2014-03-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-12-20
        相关资源
        最近更新 更多