Fit image of random size into a UIWebview (IOS)
I have used below code and its working well.
NSString *imageHTML = [[NSString alloc] initWithFormat:@"%@%@%@", @"<!DOCTYPE html>"
"<html lang=\"ja\">"
"<head>"
"<meta charset=\"UTF-8\">"
"<style type=\"text/css\">"
"html{margin:0;padding:0;}"
"body {"
"margin: 0;"
"padding: 0;"
"color: #363636;"
"font-size: 90%;"
"line-height: 1.6;"
"background: black;"
"}"
"img{"
"position: absolute;"
"top: 0;"
"bottom: 0;"
"left: 0;"
"right: 0;"
"margin: auto;"
"max-width: 100%;"
"max-height: 100%;"
"}"
"</style>"
"</head>"
"<body id=\"page\">"
"<img src='",fileUrl,@"'/> </body></html>"];
[wview_contents loadHTMLString:imageHTML baseURL:nil];
image size after applying aspect fit for the image in an UIWebView
Here is the solution that iOS provides to find the actual size after rendering the image view in the given rectangle..
Assume origImgSize is actual physical image size and targetImgSize is the rectangular area of UIImageView on the screen..
CGRect sizeBeingScaledTo = AVMakeRectWithAspectRatioInsideRect(origImgSize, CGRectMake(0, 0, targetImgSize.width, targetImgSize.height));
This gives the actual size of the image after rendering using AspectFit mode.
Related Topics
iOS Notification Trigger: Fortnightly And/Or Quarterly
Ios- Check Whether Current Time Is Between Two Times or Not
How to Properly Add Child View Controller in iOS 8 with Swift
Secure Contents in Documents Directory
Youtube Video Autoplay Inside Uiwebview
Geofire Query on User Location
Measuring Time Accurately in Swift for Comparison Across Devices
Ios-8 and Later - Uitableview Inside an Uialertcontroller
Making Phone Calls on the Iphone
How Can One Enable Keyboard Like in Imessages/Fb Messenger in Landscape Mode at iOS8
Module 'Googlemobileads' Not Found in iOS
Xcode 9 Crash When Open Storyboard
Instantiateviewcontrollerwithidentifier - Storyboard Id Set But Still Not Working
Iphone:Get the File Path Which Is Within Subfolder of Resource Folder
Setting a Rotation Point for Cgaffinetransformmakerotation Swift
iOS 7.0 and Arc: Uitableview Never Deallocated After Rows Animation