Img Css Percentage in UIWebView with NSString

Hello i need to set CSS style in my HTML NSString to fit size of image in UIWeView.

Here is codes.

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,[ stripTags:mmObject.title],myData];

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

It doesn't work with max-width:100%. I think the percentage sign is the problem. How can i do it?


% will not work if you are writing this code in any view controller you have to use px;(pixels). If you are using .js file in your app and if you write % in .js file it will work.

What you have will work fine if you escape the \% in your css string.

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;}";

If anybody needs some more elegant solution, I did create a wrapper for SWIFT. to format UIWebView text on iOS.

Need Your Help

Refreshing an excel pivot table using windows scheduler

excel scheduler

I am responsible for updating an Excel spreadsheet which pulls its information from an Access database on a daily basis. All the data that i need for my excel spreadsheet is available for me and all

Active Directory Rights Management System SDK

c# .net web-services sdk rms

I developed a DLL works as proxy between RMS Server and whom ever he wants to utilize its services programatically , The DLL works pretty fine, but the problem arises when i want to use this DLL in...