2014-03-12 53 views
0

您好,我需要在我的HTML NSString中設置CSS樣式以適合UIWeView中圖像的大小。Img Css在NSString UIWebView中的百分比

這裏是代碼。

NSString *cssCode = @"img{max-width:100%}body{font-family:Custom-One;color:white;font-size:15px;text-shadow:1px 1px 2px black;-webkit-text-size-adjust: none;}"; 

NSString *myCustomString = [NSString stringWithFormat:@"<html><head><style>%@</style></head><body><b><font color=red><center> [ %@ ]</center></b><br/><b><center>[ Title ]</center> </font></b><br/>%@<body></html>",cssCode,[self.app stripTags:mmObject.title],myData]; 

[self.myWebView loadHTMLString:myCustomString baseURL:nil]; 

它不適用於max-width:100%。我認爲百分比符號是問題所在。 我該怎麼做?

回答

1

如果您在任何視圖控制器中編寫此代碼,則必須使用px;(像素),否則無效。如果您在應用程序中使用.js文件,並且如果您在.js文件中寫入%,它將起作用。

1

如果你在你的css字符串中跳出\%,你會有什麼效果。

NSString *cssCode = @"img{max-width:100\%}body{font-family:Custom-One;color:white;font-size:15px;text-shadow:1px 1px 2px black;-webkit-text-size-adjust: none;}";