【问题标题】:How to show an UILable value/text value to HTML string in iOS?如何在 iOS 中将 UILabel 值/文本值显示为 HTML 字符串?
【发布时间】:2016-06-22 07:02:42
【问题描述】:

我有一个问题,我想在 iOS 中显示 html 文本,但我在一个标签中显示值,我将如何在 html 文本中显示它?这就是我所做的

_name.text = tutorial.title;

_name.text 我从 html 解析中得到值。

使用这个我正在显示 html 文本,但是我如何在其中传递 _name.text 值?

NSString *my=[NSString stringWithFormat:@"<html> <body> <p align='center'> <font color='red' size='3'> <strong> <u> hiii </p> </u> </srong> </font> </body> </html>"]; 

使用它我可以显示 hii 或任何使用 html 的消息,但是我如何在其中添加解析值?

【问题讨论】:

  • 您能进一步解释一下吗?你想在 UILabel 中显示 html 文本?
  • nop 我想使用 html 标签 @Joshua 显示 _name.text 标签值
  • nop 在标签 @Joshua 中显示 html 值
  • 你想在html字符串中添加标签文本吗?

标签: html objective-c nsstring


【解决方案1】:
 //setting text on label
[self.lblStatus setText:@"This is test data"];

//creating string with html format and adding label value in it
NSString *my=[NSString stringWithFormat:@"<html> <body> <p align='center'> <font color='red' size='3'> <strong> <u> %@ </p> </u> </srong> </font> </body> </html>",self.lblStatus.text];

//here i'm printing string, you can load it in webview
NSLog(@"My HTml String : %@",my);

【讨论】:

    【解决方案2】:

    我假设这是您所期望的?

     NSString *my=[NSString stringWithFormat:@"<html> <body> <p align='center'> <font color='red' size='3'> <strong> <u> {textToReplace} </p> </u> </srong> </font> </body> </html>"];
    
     my = [my stringByReplacingOccurrencesOfString:@"{textToReplace}" withString:_name.text];
    
    
    i.e.
     input.text = @"this is a test";
    
     // perform the stringReplacement
      <html> <body> <p align='center'> <font color='red' size='3'> <strong> <u> this is a test </p> </u> </srong> </font> </body> </html>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多