I'm new to the whole "iPhone Dev" world, and I am creating a simple app which has a feature to see the latest entries from a number of different Wordpress blogs.
I am able to grab encoded content ( node) from the RSS feeds and display it easily enough using a UIWebView and the loadHTMLString function.
What I cannot figure out how to do right now is change the look of the text in any way, shape, or form... I don't think it's possible for me to change the data coming back in the RSS feed, so I need to know how to do it in the code.
Thanks!
--d
There are at least two ways to change the appearance.
One is to modify the html before passing it to loadHTMLString. For example, you could insert a <link href="local.css" rel="stylesheet" type="text/css"> just before </head> using simple string replacement. You could do the same thing with a <style>...</style> tag.
html = [html stringByReplacingOccurrencesOfString:#"</head>" withString:#"<link ... /></head>"];
Another way is to call stringByEvaluatingJavaScriptFromString in webViewDidFinishLoad and do whatever you want with javascript. You have full access to the DOM through javascript and can manually create styles and assign classes.
You may need to use both together.
Related
I’m trying to make a scraper project that takes links and displays on a html page but you can’t use html tags in pyscript tag.
Is there any way to do it
What I find with printing the link is that it gives the literal string of the link and not a clickable link
This isn’t the actual code but acts as an an example of the problem
<py-script>
Var= ‘Link’
</py-script>
<body>
<a href=link>Link</a>
</body>
You have created a clickable anchor tag. Move your mouse over the text and click it.
The problem is that the pyscript.css file is overwriting the attributes of some HTML tags changing how they appear. Remove pyscript.css from your program and notice the difference.
You could add your own CSS and make the Anchor Element appear how you want. To write serious PyScript programs you will need to learn about the browser DOM, CSS, etc.
I'm using Gallerific with history plugin. In the while loop where I print all the images I want to add a facebook share button for each image using the specific image-url given by the history-plugin.
<script type="text/javascript" src="http://static.ak.fbcdn.net/connect.php/js/FB.Share"></script>
$images=mysql_query("SELECT filename FROM images etc.");
while ($row = mysql_fetch_array($images)) {
<li><a class='thumb' name='imagename' href='url-to-image' title='description' onclick='clickedThumbnail()'><img src='url-to-thumb' alt='".$row['comment']."'/></a>
<div class='caption'>
<a name=\"fb_share\" type=\"button_count\" share_url=\"http://url-to-image-made-by-the-history-plugin\">Share</a>
</div>
}
My problem is that it is only printing the facebook share button once. In the first while-loop. On the rest of the images it is printing the content of the <a>-tag ('Share') with the right attributes, but it is not clickable. I've tried without 'share' in the <a>-element but then I get nothing on the other images. But I always get the correct FB-button on the first image.
According to developers.facebook.com I only have to include the javascript once even though I'm using several Facebook buttons on one page.
I have also tried to put several facebook-buttons outside the while-loop and it works fine.
Also, when I type the direct url to the images given by the history plugin it works fine. So my conclusion is that is has to do with printing the facebook-buttons from a while-loop..?
I used this approach instead http://developers.facebook.com/docs/reference/javascript/FB.ui/
by changing some variables dynamically for each image. Works like a charm!
Thanks for the comments.
That plugin is deprecated. See: http://developers.facebook.com/docs/share/
You will want to use the share functionality that is part of the like button. See: http://developers.facebook.com/docs/reference/plugins/like/
My (MVC2) application displays several addresses in a View.
Each address contains just a subset of information, like first- and lastname. The request is that the complete address information should be displayed when the mouse is over a result.
An html template should be used therefor.
This template defines how(!) the complete address should be displayed – but it doesn’t defines what(!) should be displayed.
Means it can be assumed that the complete address is always “firstname“, “lastname”, “street”, “zipcode” and “city” (for example and to keep it simple). This will never be changed.
But for example the background color can be changed in the html template from white to green or the size of the lastname can be changed from <h1> to <h2> …
What is the best way to solve it?
I would prefer to write some shared code (keyword: ascx).
This shared code should wrap the template, would be very easy and would look like this:
<div id=”mouseOver” style="display: none;" >
X_REPLACE_X
</div>
The template would look like this simplified example:
FirstName: {Name}<br/>
Lastname: <h1>{Lastname}/<h1><br/>
ZipCode: {ZipCode}<br/>
I would then render the ascx code via “Html.RenderPartial” on the View and map each address to a javascript mouseover function.
The javascript function would replace the placeholder (like {FistName}, {LastName} , etc.) in the template, position and display it.
And thats my problem:
The template should NOT be put directly in the wrapper (ascx - code)!
Means at runtime must “X_REPLACE_X” be replaced with a somewhere on the server stored template.
Because this gives me the ability to change the template without changing and publishing the code!
How can this be managed?
Is there a much better way to solve it? Should I use instead ajax calls to get the template in a variable?
Any help would be really great!
thxs in advance!
It sounds like the best way to accommodate your display differences is to simply use different css classes. The html template used for the full information does not change and can be used for all addresses, while the differences between background colors and text size can be handled by different css settings.
Relatedly, I wouldn't handle the different text sizes by using <h1></h1> and <h2></h2> but rather a common tag (such as <span></span>) whose text size is handled via css.
I am parsing a group of post on a blog.
I have some HTML that I successfully assigned to a string. I am trying to get the HTML to display in a UITableview. However, I want it formatted.
For instance I want <br /> to actually do a line break in the table and <img scr= to actually display the picture. How can I accomplish this.
Don't ever ever ever use UIWebView in UITableView. It won't end well.
You should check out the Three20 project's TTStyledTextLabel, which will do some basic HTML formatting. I have used it with good results in the past.
i'm developing an app that will be just a wrapper for a certain book
the book is in HTML so, i want to make something like stanza,
i want to determine no. of pages given the Whole book HTML and to paginate that dynamically into views.
is there any built-in methods that can help me with that?
or
does anyone know any idea of how that can be done ?
If you only need to do this once: insert some javascript into the HTML to tell you the height of the document once it's done loading, e.g.:
alert(document.height);
and divide that by the height of your web view to get the number of pages.
You can use UIWebView to load the data, and leave the navigation/link code to paginate in the HTML.