Load image on UIWebView and scale it correctly - ios

I load an local image (tif) on to the UIWebView:
string fileName = "image.tif";
string localDocUrl = Path.Combine (NSBundle.MainBundle.BundlePath, fileName);
webView.LoadRequest(new NSUrlRequest(new NSUrl(localDocUrl, false)));
webView.ScalesPageToFit = true;
The image is bigger than the UIWebView.
Now I want that the image fits in the web view. How can I do this?

i am unable to give comment due to too less comment as i am a new user.
Plz goto nib file and check "Sceling" as "Scale page to fit"
Hope it will work

I'm not sure if this applies directly to a picture, but I had issues trying to get a webview to show correctly on the screen. This is the code that I used and hopefully it can work for you.
var webview = new UIWebView(this.View.Frame);
webview.LoadRequest(new NSUrlRequest(new NSUrl(myCustomUrl)));
this.NavigationController.PushViewController(
new UIViewController() { webview }, true);
Maybe setting the frame will help?

Related

iOS: embeded Youtube video in Webview inside UITableViewCell not playing

When my WebView is inside a normal UIView every thing works and video plays as expected. (I created a new sample project to test it.)
But when I put the WebView inside a UITableView. Its not playing. It loads the video player with video's thumbnail and big red play button. When I click play button, video won't play. The WebView goes black.
Here's my code
void LoadVideo (string videoId)
{
nfloat width = UIScreen.MainScreen.Bounds.Size.Width - 32;
nfloat height = VideoWebview.Frame.Size.Height;
string embedHtml = "<iframe width=\"{0}\" height=\"{1}\" src=\"https://www.youtube.com/embed/{2}?modestbranding=1&showinfo=0\" frameborder=\"0\" style=\"margin:-8px;padding:0;\" allowfullscreen></iframe>";
string html = string.Format (embedHtml, width, height, videoId);
Console.WriteLine (html);
VideoWebview.ScrollView.Bounces = false;
VideoWebview.LoadHtmlString (html, new Foundation.NSUrl ("https://www.youtube.com"));
}
This works fine when the WebView is not inside a UITableViewCell. What am I doing wrong here? Any help is appreciated.
Edit:
I've found that it's some issue with my project. I created a new sample project and its working inside a UITableViewCell. But in the current project that I'm working it just don't work... not in UITableViewCell, not in UIView.

Webview vertical scrollbar cuts off the content

I am using Webview in my UWP app to render some html content. The problem is, when the content is long enough to produce a scrollbar, the scrollbar would hide some of the content behind itself.
How can I fix it?
Try this code ,that's how i fixed it.
this.webView.InvokeScriptAsync("eval", new string[] { SetScrollbarScript });
string SetScrollbarScript = #"
function setScrollbar()
{
//document.body.style.overflow = 'hidden';
document.body.style.msOverflowStyle='scrollbar';
}
setScrollbar();";`

Xamarin.IOS: Can't load image from Images.xcassets

Im working on Xamarin Studio, and I have a Storyboard which contains a UIImageView, its properties are set like this :
You can notice that chosen image is called personalPhoto which exists in the Images.xcassets like this
But when I run the app in the simulator, the image isn't loaded .. and the UIImageView looks empty
Even if try to add the UIImageView programatically using this code.. it gives me the same result
UIImageView personImage = new UIImageView {
Frame = new CoreGraphics.CGRect (0, 0, 200, 200),
Image = UIImage.FromBundle("personalPhoto"),
ContentMode = UIViewContentMode.ScaleAspectFill
};
this.View.AddSubview (personImage);
So do you have any idea what is the problem .. please give me some help ..
And thanks in advance ..
Restart your iPhone or Simulator and try again.
You can also clean (Product -> clean) and try again

Load image from solution in WebView Xamarin Forms

I have inside ScrollView images and i want selected image opened in some new page and have pinch and zoom , i try webview control but i cant load image from my solution path .
void loadhtml()
{
var htmlSource = new HtmlWebViewSource {
Html = "<!DOCTYPE html>\n<html>\n<body>\n<img src=\"myproject.Images.test.jpg\">\n</body>\n</html>"
};
MyWebView.Source = htmlSource;
}
Can i load image from path where is inside my app in WebView ? Another method for pinch and zoom ?
Thanks.
You can in fact load content that is bundled into you app with the Xamarin.Forms WebView. See this link: https://developer.xamarin.com/guides/cross-platform/xamarin-forms/user-interface/webview/
I hope that helps!

Clear the content of a webview

How to clear the content of a webview?
I've tried with weburl.url = 'about:blank' but it seems not to work.
Any other ideas?
webview.src = 'about:blank'
should do what you want.

Resources