Reputation: 1295
I looked for solution on Stack Overflow but I didn't find one. My code is:
CGRect rect = _postContentView.bounds;
_postContentUIWV = [[UIWebView alloc] initWithFrame:rect];
[_postContentUIWV loadHTMLString:selectedPostCD.content baseURL:nil];
int fontSize = 30;
NSString *jsString = [[NSString alloc] initWithFormat:
@"document.getElementsByTagName('span')[0].style.webkitTextSizeAdjust='%d%%'",
fontSize];
[_postContentUIWV stringByEvaluatingJavaScriptFromString:jsString];
[_postContentView addSubview:_postContentUIWV];
And the part of HTML inside UIWebView
:
<p style="text-align: justify;">
<span style="line-height: 1.5em;">blablablablablabla</span>
</p>
My code doesn't increase the font size inside UIWebView
. How can I solve it?
Upvotes: 2
Views: 3598
Reputation: 243
Try this method:
NSString *htmlString =[NSString stringWithFormat:@"<font face='Font_name' size='30'>%@", Yourstring];
[webview loadHTMLString:htmlString baseURL:nil];
Upvotes: 1
Reputation: 1295
Moreover, you can concatenate string to existing HTML inside UIWebView
:
NSString * htmlString = @"<style>p {font-size:28px}</style>";
makeBiggerCssString = [makeBiggerCssString stringByAppendingString:
selectedPostCD.content];
[_postContentUIWV loadHTMLString: htmlString baseURL:nil];
Upvotes: 1
Reputation: 1340
Leave the code related to creation and initialization of _postContentUIWV
inside the viewDidLoad
method:
- (void)viewDidLoad
{
[super viewDidLoad];
CGRect rect = _postContentView.bounds;
_postContentUIWV = [[UIWebView alloc] initWithFrame:rect];
_postContentUIWV.delegate = self;
[_postContentUIWV loadHTMLString:selectedPostCD.content baseURL:nil];
[_postContentView addSubview:_postContentUIWV];
}
Move the code related to evaluation of jsString
to the webViewDidFinishLoad
method:
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
int fontSize = 30;
NSString *jsString = [[NSString alloc] initWithFormat:
@"document.getElementsByTagName('span')[0].style.webkitTextSizeAdjust='%d%%'",
fontSize];
[_postContentUIWV stringByEvaluatingJavaScriptFromString:jsString];
}
Upvotes: 4