Ankit Chauhan
Ankit Chauhan

Reputation: 2405

iphone : How to set Font size in webView?

I am creating HTML using following code :

NSString *string = [NSString stringWithFormat:
                        @"<html> \n" "<head> \n"
                        "<style type=\"/css\"> \n"
                        "body {font-family: \"%@\"; font-size: %@;}\n"
                        "</style> \n"
                        "</head> \n"
                        "<body>%@</body> \n"
                        "</html>",@"Helvetica",[NSNumber numberWithInt:17],
                        @"<p><i>My data</p>"];

Here I am giving [NSNumber numberWithInt:17] for font size but any change in this 17 dosen't making changes in font size of HTML.

What should I do ?

Upvotes: 1

Views: 2226

Answers (3)

Deepak Danduprolu
Deepak Danduprolu

Reputation: 44633

I think your problem was that you had the wrong style type – /css and not text/css.

"<style type=\"text/css\"> \n"

Upvotes: 3

EmptyStack
EmptyStack

Reputation: 51374

Passing [NSNumber numberWithInt:17]; doesn't passes the actual value, it just passes the object reference. So, you should be passing it like this,

font-size: %dpx;

And the value as just,

17

Upvotes: 2

Msencenb
Msencenb

Reputation: 5104

You need a unit attached to it. the CSS font-size property needs to be

font-size: 17px    

or you could also use em or percentages

Upvotes: 4

Related Questions