Substitute the HTML String

Currently I am involved in a project that utilizes a webView in Swift 4. The project retrieves an HTML string from a web-service, which includes text and images. My goal is to modify the font size of the text, change the background color, and adjust the image sizes within the entire HTML string. For example, if the font size appears 10 times, I want to apply the font change uniformly across all instances. I will provide both the HTML string and its output for reference.

<p class=\"MsoNormal\" style='margin-bottom:0in;margin-bottom:.0001pt'> </p><div align=\"center\"><table class=\"MsoTableGrid\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" style='border-collapse:collapse;border:none'>  <tr style='height:12.5pt'>   <td width=\"216\" valign=\"top\" style='width:2.25in;border:solid #4BACC6 1.0pt;   background:#DAEEF3;padding:0in 5...

Answer №1

Finally found the solution without needing to adjust font size or image size. Simply insert the following HTML code and input your own HTML in between. When loaded into the webview, your font size will display normally and images will also be displayed correctly. Check out the image I implemented in my app.

let fetchedData = "your HTML string retrieved from web API"

"<html><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><style type=\"text/css\">span{top:0 !important;}img{max-width: 100%; width:auto; height: auto; zoom: \(aZoom); vertical-align:middle !important}body{color: #000}iframe{ min-width: 100%; width: 100px; *width: 100%;}</iframe></style></head><body>\(fetchedData)</body></html>"

Answer №2

If you want to customize the spacing in your HTML file, simply adjust the top margin values from 15.0pt to 4.0pt and from 6.0pt to 2.0pt. You can also change the background color to any preferred option.

Additionally, if you wish to modify the image dimensions, just specify the height and width within the img tag.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using multiple html files with ui-router's ui-view feature

Is it possible to create a complex UI using multiple HTML files with ui-view in AngularJS? I am trying to achieve a layout similar to this: I attempted to implement something on Plunker, but it seems like I'm struggling to grasp the underlying concep ...

The overflow:hidden property prevents me from being able to scroll down the rest of my webpage

@import url('https://fonts.googleapis.com/css?family=Indie+Flower|Lobster|Open+Sans+Condensed:300|Roboto+Condensed&display=swap'); * { margin: 0; padding: 0; } html,body { height: 100%; width: 100%; margin: 0px; padding: 0px; ...

How can I remove the bouncing effect of the top bar in Chrome when scrolling in Three

There is a frustrating problem I am encountering on my website with the joystick control. Whenever I try to move my joystick down, Chrome triggers either the refresh dropdown or the top bar bounces and goes in and out of fullscreen mode. ...

"Step-by-step guide to building a webgrid or table to organize and display your

These are the HTML codes I have created: <table> <tr> <td><label style="text-align:left">Product Code:</label></td> <td><input type="text" id="productCode" value="" /> </td> </tr> & ...

Align the menu at the bottom of the navbar using Bootstrap

I'm looking for a way to adjust the alignment of the menu text within the Bootstrap 3 navbar. Here is my current code: <nav class="navbar navbar-default"> <div class="container"> <div class="navbar-header"> ...

The lack of search results on Google Custom Search could be due to issues with META tags

I have a website and I've successfully integrated Google Custom Search following all the provided instructions. Although I indexed my site three months ago, the custom search still shows no results. Even after adding sitemap.xml, there has been no i ...

Steps for organizing a list based on the number of clicks

I've created an HTML list with images of political party logos. Each logo is a grid item that can be clicked on. I want to sort the list based on the number of clicks each logo receives, essentially ranking them by popularity. However, I'm not su ...

Each page is restricted to containing only a single server-side Form tag

I inserted a page with HTML code into a master page and encountered this error when I tried to launch the page. I'm unsure of what I did wrong! <%@ Page Title="" Language="C#" MasterPageFile="~/YourGuruMaster.master" AutoEventWireup="true" Cod ...

The ball takes a bounce over the edge of the playing field

In my latest program update, I am facing an issue with the maxTop variable in my box div. It seems to be returning a NaN value, and I'm struggling to figure out why. The problem I'm encountering is that when the ball moves, it bounces off the le ...

Enhance the appearance of an angular custom component with unique styling

I have developed a unique custom angular element called my-component and in its stylesheet I've added the following: :host { display: inline-block; width: 55px; } Now, when using my-component in another component's template, I tried to ...

Tips for Integrating a Facebook Shop Page into Your Website

Can a Facebook shop page be integrated into a website? Any guidance on how to accomplish this task would be greatly valued. ...

Tap on the Dropdown Menu to access the Responsive design feature

Currently, I am working on perfecting a responsive navigation menu. My goal is to have the drop-down menu appear when the menu icon is clicked, as opposed to the hover effect. I am utilizing a Google jQuery script, but I am unsure if the drop-down functi ...

Utilizing a percentage for the border-width property

I want to remove a triangle from the bottom of a div using a CSS trick involving borders. This involves creating a border with one transparent side and coloring the other sides to create the triangle effect. The issue I'm facing is that the div has a ...

Leveraging JavaScript to change the input value by appending the character "#"

I am looking to modify the input value by adding a "#" in front of each word, but I am facing issues with handling spaces properly. function addHash(input) { var text = input.value.replace('#', ''); var words = text.split(" "); ...

Alignment of slider arrows in a CSS carousel with Bootstrap 4.1.1

Is there a way to position the carousel control arrows at the left and right ends of the screen in Bootstrap 4.1.1? I attempted the code below but it didn't yield the desired result. .carousel-control .icon-prev{ left: 5px } .carousel-control .icon ...

Adding a Sequence of Class Names to <li> Elements with JavaScript

How can you easily generate sequential class names in a for loop? ...

Generate a new row for every value in a C# dropdown either before or after a Pipe character

I am facing a challenge with the custom attribute values for products in my database. To store these values, I save them as a character-separated list using the pipe symbol to separate each size. For instance, let's consider an Orange Dress with a cu ...

"Enhancing User Experience with Hover Effects in HTML using .common

I'm pretty new to coding and currently working on a Github repository. On the same page, I have 12 clickBoxes that each have a hover effect applied where a PNG appears upon hovering. However, I've run into an issue where either the hover effect w ...

Session availability extends to subdomains, even though it may not be visible in a physical

Currently in the process of building a website Red Sec using a single account for all subdomains: Latest Updates Community Forum Personal Blog News Feed Support Us All pages share the same layout with different content by linking them to . Below i ...

Height of Parent Div minus Margin Top equal to 100%

I am working on a layout that requires three divs with different heights and header sizes to be positioned 100% from the top of their parent, while taking into account the height of the headers. I could use jQuery to achieve this, but since it's a res ...