1
0

EmbedSample.iOS.cs 1.1 KB

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