SampleViewController.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using System.Drawing;
  3. #if __UNIFIED__
  4. using Foundation;
  5. using UIKit;
  6. #else
  7. using MonoTouch.Foundation;
  8. using MonoTouch.UIKit;
  9. using nint=System.Int32;
  10. #endif
  11. using SDWebImage;
  12. namespace SDWebImageSimpleSample
  13. {
  14. public partial class SampleViewController : UIViewController
  15. {
  16. public SampleViewController () : base ("SampleViewController", null)
  17. {
  18. }
  19. public override void DidReceiveMemoryWarning ()
  20. {
  21. // Releases the view if it doesn't have a superview.
  22. base.DidReceiveMemoryWarning ();
  23. // Release any cached data, images, etc that aren't in use.
  24. }
  25. public override void ViewDidLoad ()
  26. {
  27. base.ViewDidLoad ();
  28. btnDownload.TouchUpInside += (sender, e) => imageView.SetImage (
  29. new NSUrl ("http://goo.gl/1g7jP"), null, SDWebImageOptions.ProgressiveDownload,
  30. ProgressHandler, CompletedHandler
  31. );
  32. }
  33. void ProgressHandler (nint receivedSize, nint expectedSize)
  34. {
  35. if (expectedSize > 0) {
  36. InvokeOnMainThread (()=> {
  37. float progress = (float)receivedSize / (float)expectedSize;
  38. progressBar.SetProgress (progress, true);
  39. lblPercent.Text = "Downloading...";
  40. });
  41. }
  42. }
  43. void CompletedHandler (UIImage image, NSError error, SDImageCacheType cacheType, NSUrl url)
  44. {
  45. InvokeOnMainThread (()=> lblPercent.Text = "Download Completed");
  46. }
  47. }
  48. }