protected override void OnElementChanged(VisualElementChangedEventArgs e) { base.OnElementChanged(e); if (Element != null) { var materialView = UIStoryboard.FromName("Main", null).InstantiateViewController("ViewController").View; NativeView.AddSubview(materialView); } }
public override UIView CreateView() { _view = new NativeView(); _view.TouchesBeganEvent += HandleTouchesBeganEvent; _view.TouchesEndedEvent += HandleTouchesEndedEvent; _view.TouchesCancelledEvent += HandleTouchesCancelledEvent; foreach (var control in _controls) { _view.AddSubview(control.CreateView()); } return(_view); }
void UpdateContent() { _ = NativeView ?? throw new InvalidOperationException($"{nameof(NativeView)} should have been set by base class."); _ = VirtualView ?? throw new InvalidOperationException($"{nameof(VirtualView)} should have been set by base class."); _ = MauiContext ?? throw new InvalidOperationException($"{nameof(MauiContext)} should have been set by base class."); // Cleanup the old view when reused NativeView.ClearSubviews(); if (VirtualView.PresentedContent is IView view) { NativeView.AddSubview(view.ToNative(MauiContext)); } }
protected override void OnElementChanged(VisualElementChangedEventArgs e) { base.OnElementChanged(e); if (ViewController != null) { NSArray items = NSArray.FromStrings(new string[] { "Courses", "Favourite", "Recent" }); UISegmentedControl segmentedControl = new UISegmentedControl(items) { Frame = new CGRect(50, 20, NativeView.Bounds.Width - 100, 35) }; segmentedControl.SelectedSegment = 0; segmentedControl.TintColor = UIColor.Red; segmentedControl.ApportionsSegmentWidthsByContent = true; //Change the width of the segment based on the content of the segment segmentedControl.AddTarget(this, new Selector("ValueChanged:"), UIControlEvent.ValueChanged); NativeView.AddSubview(segmentedControl); } }
protected override void OnElementChanged(VisualElementChangedEventArgs e) { base.OnElementChanged(e); if (Spinner == null) { Spinner = new UIActivityIndicatorView { ActivityIndicatorViewStyle = UIActivityIndicatorViewStyle.WhiteLarge, BackgroundColor = UIColor.Gray, }; Spinner.Layer.CornerRadius = 10; NativeView.AddSubview(Spinner); Spinner.TranslatesAutoresizingMaskIntoConstraints = false; NativeView.AddConstraint(NSLayoutConstraint.Create( Spinner, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, NativeView, NSLayoutAttribute.CenterX, (nfloat)1.0, (nfloat)0.0)); NativeView.AddConstraint(NSLayoutConstraint.Create( Spinner, NSLayoutAttribute.CenterY, NSLayoutRelation.Equal, NativeView, NSLayoutAttribute.CenterY, (nfloat)1.0, (nfloat)0.0)); NativeView.AddConstraint(NSLayoutConstraint.Create( Spinner, NSLayoutAttribute.Width, NSLayoutRelation.Equal, (nfloat)1.0, (nfloat)100)); NativeView.AddConstraint(NSLayoutConstraint.Create( Spinner, NSLayoutAttribute.Height, NSLayoutRelation.Equal, (nfloat)1.0, (nfloat)100)); } if (e.NewElement is PopContentPage page) { page.PropertyChanged += IsBusyChanged; SetIsBusy(); } if (e.OldElement is PopContentPage page2) { page2.PropertyChanged -= IsBusyChanged; } }
void UpdateIndicator() { if (VirtualView is ITemplatedIndicatorView iTemplatedIndicatorView) { var indicatorsLayoutOverride = iTemplatedIndicatorView.IndicatorsLayoutOverride; UIView?handler; if (MauiContext != null && indicatorsLayoutOverride != null) { ClearIndicators(); handler = indicatorsLayoutOverride.ToNative(MauiContext); NativeView.AddSubview(handler); } } void ClearIndicators() { foreach (var child in NativeView.Subviews) { child.RemoveFromSuperview(); } } }
public override void Draw(CGRect rect) { base.Draw(rect); if (Element == null) { return; } var cx = rect.Width / 2f; var cy = rect.Height / 2f; var colorSpace = CGColorSpace.CreateDeviceRGB(); var context = UIGraphics.GetCurrentContext(); var gradientColors = new CGColor[] { UIColor.LightGray.CGColor, Element.BackgroundColor.ToCGColor() }; var gradientLocations = new nfloat[] { 0f, 1f }; var gradient = new CGGradient(colorSpace, gradientColors, gradientLocations); var shadow = new NSShadow() { ShadowColor = UIColor.Gray, ShadowOffset = new CGSize(3, 3), ShadowBlurRadius = 3 }; // Draw the hexagon (POINTY-TOP ONLY) var radius = Element.Radius; if (Element.BorderColor.A > 0 && Element.BorderSize > 0) { radius -= Element.BorderSize / 2f; } var points = new List <CGPoint>(); for (int i = 0; i < 6; ++i) { points.Add(new CGPoint(cx + radius * Math.Cos((i * 60 - 30) * Math.PI / 180f), cy + radius * Math.Sin((i * 60 - 30) * Math.PI / 180f))); } var midPoint = new CGPoint(0.5 * (points[0].X + points[1].X), 0.5 * (points[0].Y + points[1].Y)); var path = new CGPath(); path.MoveToPoint(midPoint); for (var i = 0; i < points.Count; ++i) { path.AddLineToPoint(new CGPoint(points[(i + 1) % points.Count].X, points[(i + 1) % points.Count].Y)); } path.CloseSubpath(); context.AddPath(path); //CoreAnimation.CAShapeLayer mask = new CoreAnimation.CAShapeLayer(); //context.SetShadow(shadow.ShadowOffset, shadow.ShadowBlurRadius, UIColor.Gray.CGColor); context.SetFillColor(Element.BackgroundColor.ToCGColor()); if (Element.BorderColor.A > 0 && Element.BorderSize > 0) { context.SetLineWidth((nfloat)Element.BorderSize); context.SetStrokeColor(Element.BorderColor.ToCGColor()); context.DrawPath(CGPathDrawingMode.FillStroke); } else { context.DrawPath(CGPathDrawingMode.Fill); } //context.SaveState(); //context.BeginTransparencyLayer(); //path.AddClip(); //context.DrawLinearGradient(gradient, points[0], points[1], CGGradientDrawingOptions.DrawsAfterEndLocation); //context.EndTransparencyLayer(); //context.RestoreState(); // Draw Text if (!String.IsNullOrEmpty(Element.FAText)) { double eigthHeight = rect.Height / 8; double quarterHeight = rect.Height / 4; double threeEights = eigthHeight * 3; if (!String.IsNullOrEmpty(Element.Text)) { // FAText Icon with Text //CGRect faRect = new CGRect(rect.X, rect.Y + eigthHeight, rect.Width, threeEights); // no overlap CGRect faRect = new CGRect(rect.X, rect.Y + eigthHeight, rect.Width, rect.Height / 2); // bottom of rect slightly overlaps with text-label UILabel faLabel = new UILabel(faRect) { Text = Element.FAText, TextAlignment = UITextAlignment.Center, TextColor = Element.TextColor.ToUIColor(), Font = UIFont.FromName(Element.FAFontFamily, (nfloat)Element.FAFontSize) }; CGRect labelRect = new CGRect(rect.X, rect.Height / 2, rect.Width, quarterHeight); UILabel label = new UILabel(labelRect) { Text = Element.Text, TextAlignment = UITextAlignment.Center, TextColor = Element.TextColor.ToUIColor(), Font = UIFont.FromName(Element.FontFamily, (nfloat)Element.FontSize) }; NativeView.AddSubviews(new UIView[] { faLabel, label }); } else { if (Element.IsMenu) { // FAText Icon only (used for IsMenu property of HexagonLayout) CGRect faRect = new CGRect(rect.X, rect.Y + eigthHeight, rect.Width, rect.Height / 2); UILabel faLabel = new UILabel(faRect) { Text = Element.FAText, TextAlignment = UITextAlignment.Center, TextColor = Element.TextColor.ToUIColor(), Font = UIFont.FromName(Element.FAFontFamily, (nfloat)Element.FAFontSize) }; NativeView.AddSubview(faLabel); } else { // FAText Icon only (centered) CGRect faRect = new CGRect(rect.X, rect.Y, rect.Width, rect.Height); UILabel faLabel = new UILabel(faRect) { Text = Element.FAText, TextAlignment = UITextAlignment.Center, TextColor = Element.TextColor.ToUIColor(), Font = UIFont.FromName(Element.FAFontFamily, (nfloat)Element.FAFontSize) }; NativeView.AddSubview(faLabel); } } } else { UILabel label = new UILabel(rect) { Text = Element.Text, TextAlignment = UITextAlignment.Center, TextColor = Element.TextColor.ToUIColor(), Font = UIFont.FromName(Element.FontFamily, (nfloat)Element.FontSize) }; NativeView.AddSubview(label); } }