I loaded HTML
to my UIWebView
that including both Text
and Images
.
Text
is fit to UIWebView
and Images
are not fit to UIWebView
.
It's too large in UIWebView
.
It's showing scroll bar at the end of the UIWebView
.
I want to adjust image fit size in UWebView. So i tested with following codes.
self.myWebView.scalesPageToFit = YES;
However it's fixed including Text and Text is too small to read and Images are fixed.
I want to set Text Normally and only want to fit size Image in UIWeView
.
How can i do it?
I have solve this problem using css. The css contained within the style tags below will make sure to automatically resize your images maintaining aspect ratio for the width of the UIWebView. Hope this helps!
NSString *strTemplateHTML = [NSString stringWithFormat:@"<html><head><style>img{max-width:100%%;height:auto !important;width:auto !important;};</style></head><body style='margin:0; padding:0;'>%@</body></html>", @"insert your html content here"];
[webView loadHTMLString:strTemplateHTML baseURL:nil];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With