我有一个问题,我想在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>"];
使用这个我能够使用html显示hii或任何一条消息,但我如何在此添加解析值?
答案 0 :(得分:1)
我假设这是你所期待的?
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>
答案 1 :(得分: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);