Is it possible to implement two distinct styles within a single UIWebView on IOS 5?

Here is my code:

         CGRect frame9 = CGRectMake(392, 100, 320, 329);

         UIWebView * webView = [[UIWebView alloc] initWithFrame:frame9];
         [webView setBackgroundColor:[UIColor clearColor]];

         NSString* htmlContentString = [NSString stringWithFormat:
                                @"<html>"
                                "<style type=\"text/css\">"
                                " body   {background-color:transparent; font-family:Helvetica; color: #c8b981 ; font-size:18px;text-align :justify;} .titulo {background-color:transparent; font-family:Helvetica; color: #42382b ; font-size:11px;}"
                                "</style>"
                                "<body>"
                                "<p class = titulo > %@ </p>"
                                "<p>%@</p>"
                                "<p2 { background-color:transparent; font-family:Helvetica; color: #42382b ; font-size:11px;text-align :left};> %@ </p2>"                                    
                                "<p>%@</p>"
                                "<h2 style =background-color:transparent; font-family:Helvetica; color: #42382b ; font-size:11px;text-align :left;> %@ </h2>"                                    
                                "<p>%@</p>"
                                "</body></html>",@"A LA VISTA", vino.vista,@"POR LA NARIZ" ,vino.nariz,@"AL PALADAR" , vino.paladar];

         [webView loadHTMLString:htmlContentString baseURL:nil];

         webView.backgroundColor = [UIColor clearColor];
         [webView setOpaque:NO];
         webView.scrollView.bounces = NO;
         [subview addSubview:webView];

My intention is to apply specific styles for the Body and Titles in my HTML content, but I'm facing issues achieving this. Any insights would be appreciated.

Thank you.

Answer №1

Your HTML code could use some improvements, especially when it comes to utilizing classes for your paragraphs (p tags). However, it seems like you're on the right track with what you're trying to achieve.

NSString *htmlUI = @"<html><style type='text/css\'> body { background-color:transparent; font-family:Helvetica; color: #c8b981; font-size:18px;text-align:justify} .class1 { background-color:transparent; font-family:Helvetica; color: #0000FF; font-size:11px; } .class2 { background-color:transparent; font-family:Helvetica; color: #FF0000 ; font-size:11px; }' </style><body> <p class='class1'> Class1 </p><p class='class2'> Class2 </p><p> No Class </p></body></html>";

[webView loadHTMLString:htmlUI baseURL:nil];

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

Welcome to the interactive homepage featuring multitouch authentication

I am looking to design a homepage that is interactive based on touch input. For instance, if the user uses 5 fingers to touch the screen, similar to the green circles in the image below, they will be redirected to a specific homepage. If they touch in a di ...

JavaScript condensed into a single table cell rather than occupying an entire webpage

Hey there, I have a simple question that I can't seem to find the answer to anywhere. I'm working on a JavaScript function that pulls data from my database and I want it to display in one cell of a table instead of outputting to the entire page. ...

HTML formatter in VS Code that maintains inline comments intact

Currently on the hunt for a reliable HTML formatter plugin for VS Code that won't mess up existing HTML code with inline comments like this: <div>hello</div><!-- class="world" --> Don't want it to end up like this: <div> ...

What steps should I take to ensure that my Material Design Icon Fonts are appearing correctly on the screen?

I can't seem to get my icons to display properly. I have included the path like this: <link href="material/vendors/material-icons/material-design-iconic-font.min.css" rel="stylesheet"> This is what I currently see: But thi ...

Utilizing Ajax in ASP.NET to Execute a Controller's Void Method when Clicking a Button

I have a project for a .ASP MVC Web Application. My goal is to trigger a void method in the controller class when I click a button using AJAX. There is no need for any input or output data, just simply creating a PDF file and saving it locally. Currently, ...

Prepare the writing area for input

My inputs have validation indicators, such as a green tick or red cross, placed at the very right of the input (inside the input). Is there a way to specify the writing space inside an input without restricting the number of characters that can be enter ...

Bootstrap 4.0. When it comes to buttons, they seem to have trouble cooperating with other DIV elements

Today is my first time seeking help on StackOverflow: I'm encountering an issue with my website where the floating arrow at the bottom of the page is obstructing my ability to click on buttons. Whether it's a Bootstrap button or HTML button, non ...

Tips for making a 2D grid on a webpage

Is there a way to implement a 10x10 grid on a webpage where users can click anywhere on the grid and have their (x, y) position recorded with one decimal place accuracy, covering values between 0.0-10.0 or 0.1-9.9? Appreciate any guidance! ...

Issue with right-to-left (RTL) support in iOS 9.2

My code was functioning properly on iOS 9.0 and 9.1, but after updating to 9.2, it is no longer working as expected. To ensure compatibility with older versions, I am utilizing CGAffineTransform. if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"9.0")) { [ ...

The UIScrollView object is being passed by reference, without being returned

There's an interesting situation I'm facing: I have a UINavigationController that contains a UIViewController (mainVC) with a UIView (mainView) that holds a UIScrollView (scrollView). In the mainView, there's a fullscreen button that when ...

Difficulty Encountered when Using Colorbox in Internet Explorer (all iterations)

I've been struggling to get Colorbox working properly on this particular page, even after spending more time than anticipated. The link to the page has been removed for privacy reasons. There's a Colorbox test link at the bottom right corner tha ...

Navigate to a specific element on a webpage upon the page's initial load in Angular 2

Is there a way to navigate from one page to another and instantly jump to a specific control in the middle of the destination page? Typically, we would use a hashtag "#" followed by the name or ID of the control. Unfortunately, this method doesn't wo ...

"Using conditional statements to check for specific value ranges and properly handling cases where the result is undefined

Currently, I am working on a function that prompts the user to input a number and then displays a calculated score after they click a button. The score is based on the value entered by the user. While constructing this feature, I have pondered whether IF ...

Is there a way to efficiently parse HTML data returned as JSON in the browser using Cordova/Ionic?

Currently, I am retrieving data from a Drupal service and using AngularJS along with the ionic framework to create a hybrid app for mobile platforms, leveraging Cordova or Phonegap. You can check out my code on codepen: http://codepen.io/BruceWhealtonSWE/p ...

The HTML document is having trouble establishing a connection with socketio

I currently hold an HTML file within my local file system, presented as follows: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Example of a Minimal Working File</title> ...

Techniques for retrieving elements from HTML using jQuery

I'm developing a feature that allows users to add videos to playlists by clicking on a link in a popover. The challenge I'm facing is extracting the video_id and the selected playlist when the user interacts with the popover. Any tips on how to a ...

Why does the second :nth-child rule have more importance over the others in my CSS code

I am seeking clarification on the implementation of :nth-child() in CSS. Consider the following HTML structure: <div class="parent"> <div class="child">child</div> <div class="child">child</div> <div class="child"&g ...

Exploring viewWillLayoutSubviews and device rotation

I have encountered a challenge with positioning views in my app using viewWillLayoutSubviews. A recent request requires the app to support all orientations, which I thought would be straightforward with the code CGRect rotatedFrame = [self.view convertRect ...

How to create a full-width and full-height background image in a div using CSS

When using a bootstrap template, I encountered an issue with adding an image as a background. Here is the CSS code: background:url(../images/banner.png) no-repeat; background-size: 100%; The problem with these CSS rules is that the image gets clipped and ...

Issue with Laravel project: Views are not updating after code changes

Despite my efforts to clear and refresh everything, my Laravel project is not reflecting the changes. I have attempted clearing the view and deleting files manually. I also ran cache:clear, changed the root folder name, but the project continues to displa ...