Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6770369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:18:15+00:00 2026-05-26T15:18:15+00:00

I’m developing an iOS app who loads the content of a html string with

  • 0

I’m developing an iOS app who loads the content of a html string with a CSS style sheet into a UIWebView but I have problems when I use the percentage ‘%’ to define the width of a image. It just doesn’t work!

- (void) loadHTMLContent {

NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];


textFontSize = 120;

NSString *imggt;
if (item.imggt) 
    imggt = [NSString stringWithFormat:@"<br /><img src='%@' />",item.imggt];
else
    imggt = @"";

NSString *cssCode = [NSString stringWithFormat:@" \n"
                       "body{ font-family: Georgia; color: #333; margin: 0; padding: 0; line-height: 1.2em; } \n"
                       "h4, h3, h5{ margin: 0 0 5px 0; padding: 0em; text-shadow: 2px 2px 2px rgba(255, 255, 255, 0.8); } \n"
                       "h3{ font-family: Helvetica; font-size: 1.2em; letter-spacing: -1px; } \n"
                       "h3, #autor { color: #00365B; }   \n"
                       "h4,h5{ font-weight: normal; font-size: 0.75em; }\n"
                       "h4{ color: #0069AA; } \n"
                       "h5{ text-align:justify; } \n"
                       "#zigzag { height:15px; background-image:url('zigzag.png');background-repeat:repeat-x; }\n"
                       "#destacados, #cuerpo{ padding: 0 10px; } \n"
                       "#destacados{ background-image:url('fndNoticia.png'); padding-bottom: 29px; margin-bottom: 0px; } \n"
                       "#destacados img { width: 97%; text-align:center; margin: 0 auto; border: 8px solid #FFF; } \n"
                       "#fecha_autor{ font-size: 0.75em; border-bottom: 1px solid #D7D7D7; height: 20px; padding-bottom: 8px; margin: 13px 0; } \n"
                       "#fecha{ color: #666;} \n"
                       "#autor{ float: right; } \n"
                       "#texto{ font-size: 0.80em; line-height: 1.2em; text-align:justify; } \n"];

NSString *htmlCode = [NSString stringWithFormat:@" \n"

                      "<html> \n"
                      "     <head> \n"
                      "     <title></title> \n"
                      "     <style>%@</style></head> \n" //CSS
                      "     <body> \n"
                      "         <div id='destacados'> \n"
                      "             <br /><h4>%@</h4> \n"         //Category
                      "             <h3>%@</h3> \n"         //Title
                      "             <h5>%@</h5>%@ \n"         //Subtitle & Imggt in HTML
                      "         </div> \n"
                      "          <div id='zigzag'>&nbsp;</div> \n"
                      "         <div id='cuerpo'> \n"
                      "             <div id='fecha_autor'> \n"
                      "                 <span id='fecha'>%@</span> \n" //Date
                      "                 <span id='author'>%@</span> \n" //Author
                      "             </div> \n"
                      "             <div id='texto'>%@</div> \n"
                      "         </div> \n"
                      "         %@ \n" //Nielsen code
                      "     </body> \n"
                      "</html>  \n",cssCode,item.category,item.title,item.subtitle,imggt,item.pubDate,item.author,[item.text stringByReplacingOccurrencesOfString:@"[br]" withString:@"<br />"],[AppStaticData getNielsenSiteCensusHTMLImageOfArticle:item.url]];  

[webView loadHTMLString:htmlCode baseURL:baseURL];

} 

The CSS & HTML code tested on a browser works:

iOs and Chrome browsers

The problem seems to be here:

  "#destacados img { width: 97%; text-align:center; margin: 0 auto; border: 8px solid #FFF; } \n"

Seems that I can’t use percentages to set the value of the image. Why? Is there other way to escale the original image relatively to the container size?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:18:15+00:00Added an answer on May 26, 2026 at 3:18 pm

    You have to escape the ‘%’ in your css code, before you build the [NSString stringWithFormat]. In case you don’t even need a string build from format a simple

    NSString *cssCode = @"your css {}";
    

    should work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
i got an object with contents of html markup in it, for example: string
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.