基于交换机,在运行时在代码中将html添加到UI Web视图 [英] Adding html to a ui web view at runtime in code, based on a switch

查看:159
本文介绍了基于交换机,在运行时在代码中将html添加到UI Web视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将文本添加到uiwebview中,并在没有单独的html文件的情况下更改此视图中的文本和颜色?所以我在switch语句中定义html文件中的whats?我现在使用标签来做这件事,但我不能在标签中使用多种颜色,所以我需要使用html,因为核心文本看起来相当复杂。

 switch(counter)
{
case 0:
titleLabel.text = @需要多于一种颜色;
休息;
案例1:
titleLabel.text = @需要多于一种颜色;
休息;

等等...



我可以以某种方式定义这些开关中的代码中的标签中的html文件中的whats,而不是单独的html文件?如果是这样,我该怎么做?



干杯,

<刘易斯


<假设你的HTML包含一个名为myCssClass的CSS类,并在其中指定了颜色和标签: $ p> < label id =myTextElement>一个标签< / label>

您可以使用如下代码以编程方式执行javascript以设置不同的CSS类:

  UIWebView * webView; 



[webView stringByEvaluatingJavaScriptFromString:@document.getElementById(\myTextElement \)。className = \myCssClass\;];虽然老实说,如果你在CoreText上观看WWDC 2012的视频,你可能不那么害怕......


$ b $ p>

p>

Is it possible for me to add text to a uiwebview and change the text and colours in this view without having separate html files? So I define whats in the html file in a switch statement? I do this at the moment using labels, but I can't have more than one colour in a label so I need to use html, as core text looks quite complicated.

switch (counter)
{
    case 0:
        titleLabel.text = @"needs to be more than one colour";
      break;
    case 1:
        titleLabel.text = @"needs to be more than one colour";
        break;

and so on...

Can I in some way define whats in a html file in tags in the code in these switches rather than having seperate html files? If so how would I do this?

Cheers,

Lewis

解决方案

Assuming your HTML contains a CSS class called myCssClass where you specify your colors, and a label:

<label id="myTextElement">A Label</label>

You can programmatically execute javascript to set a different CSS class using code like this:

UIWebView *webView; 
.
.
.
[webView stringByEvaluatingJavaScriptFromString:@"document.getElementById(\"myTextElement\").className = \"myCssClass\";"];

though honestly if you watch the WWDC 2012 videos on CoreText you might be less intimidated...

这篇关于基于交换机,在运行时在代码中将html添加到UI Web视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆