Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iOS的NSString中将HTML与CSS连接起来?_Html_Ios_Css_Objective C - Fatal编程技术网

如何在iOS的NSString中将HTML与CSS连接起来?

如何在iOS的NSString中将HTML与CSS连接起来?,html,ios,css,objective-c,Html,Ios,Css,Objective C,我正在从服务器获取作为NSString的HTML。我需要在HTML上应用CSS。我试过的 NSString *htmlString = @"This is an example of a lorem ipsum dolor longer question that has about twenty-two words in it, est veniam dolorum?"; NSString *htmlStringQuestion = [NSString stringWithFormat:@

我正在从服务器获取作为NSString的HTML。我需要在HTML上应用CSS。我试过的

NSString *htmlString = @"This is an example of a lorem ipsum dolor longer question that has about twenty-two words in it, est veniam dolorum?";


NSString *htmlStringQuestion = [NSString stringWithFormat:@"<style type='text/css'>* {padding:0px; margin:0px;} div.ContentWrapper {width:100%; height:100%; text-align:center; display:table;}div.ContentArea {display:table-cell; vertical-align:middle; padding:0 5%; background:#ff0000;color: #FF0; font-size:30; font-family: Baskerville;}</style><div class='ContentWrapper'><div class='ContentArea'><p>%@</p></div></div>", htmlString];
NSString*htmlString=@“这是一个lorem ipsum dolor较长问题的示例,其中包含大约22个单词,est veniam dolorum?”;
NSString*htmlStringQuestion=[NSString stringWithFormat:@“{padding:0px;margin:0px;}div.ContentWrapper{width:100%;height:100%;text align:center;display:table;}div.ContentArea{display:table cell;垂直对齐:middle;padding:05%;背景:#ff0000;颜色:#FF0;字体大小:30;字体系列:Baskerville;}%@

”,htmlString];
现在它发出警告


谢谢。

您需要通过将格式字符串中的每个
%%
文本设为
%%
来正确转义。如果格式字符串中有任何双引号,则需要通过预加反斜杠(如
\”

来转义这些双引号。您需要从
htmlStringQuestion
中转义所有特殊字符(特殊字符为:
/
%
;等)所以,如果我删除这些字符,它将失去CSS或HTML的本质。当我们删除标记时,字符的大小并不是删除它们。你可以通过在它们前面添加一个“\”来对它们进行转义。看看这个:这是local String@Bassem,所以我需要应用CSS,如果我删除这个%,它将不会像CSS一样起作用。@Bassem不,你转义ea通过添加第二个%%更改了ch%,您没有添加反斜杠。