EmbedSample.iOS.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System;
  2. using Avalonia.Platform;
  3. using CoreGraphics;
  4. using Foundation;
  5. using UIKit;
  6. using WebKit;
  7. using Avalonia.iOS;
  8. using ControlCatalog.Pages;
  9. namespace ControlCatalog;
  10. public class EmbedSampleIOS : INativeDemoControl
  11. {
  12. public IPlatformHandle CreateControl(bool isSecond, IPlatformHandle parent, Func<IPlatformHandle> createDefault)
  13. {
  14. if (isSecond)
  15. {
  16. var webView = new WKWebView(CGRect.Empty, new WKWebViewConfiguration());
  17. webView.LoadRequest(new NSUrlRequest(new NSUrl("https://www.apple.com/")));
  18. return new UIViewControlHandle(webView);
  19. }
  20. else
  21. {
  22. var button = new UIButton();
  23. var clickCount = 0;
  24. button.SetTitle("Hello world", UIControlState.Normal);
  25. button.BackgroundColor = UIColor.Blue;
  26. button.AddTarget((_, _) =>
  27. {
  28. clickCount++;
  29. button.SetTitle($"Click count {clickCount}", UIControlState.Normal);
  30. }, UIControlEvent.TouchDown);
  31. return new UIViewControlHandle(button);
  32. }
  33. }
  34. }