/// <summary> /// Creates a new gradient layer and inserts it as a subview if a gradient layer doesn't already exist. /// If one does exist, the existing one is updated. /// </summary> /// <param name="view">The native view the gradient fill is being applied to</param> /// <param name="gradient">The <see cref="T:XFGloss.Gradient"/> instance to copy the fill parameters from</param> static public void CreateGradientLayer(UIView view, Gradient gradient) { // Clear any previously-assigned background color view.BackgroundColor = UIColor.Clear; XFGlossGradientLayer gradientLayer = GetGradientLayer(view); // Create or update the layer as needed if a new gradient was passed to us bool insertLayer = false; if (gradientLayer == null) { gradientLayer = new XFGlossGradientLayer(view, gradient); insertLayer = true; } else { gradientLayer.GradientSource = gradient; } // Insert the layer if we created a new one if (insertLayer) { view.Layer.InsertSublayer(gradientLayer, 0); } }
/// <summary> /// Dispose any created resources and prepare the instance for garbage collection /// </summary> /// <param name="disposing">If set to <c>true</c>, dispose any created resources</param> protected override void Dispose(bool disposing) { if (disposing) { XFGlossGradientLayer.RemoveGradientLayer(this); } base.Dispose(disposing); }
/// <summary> /// UIView override to update our gradient layer's size to match our view's bounds whenever the bounds are /// changing /// </summary> public override void LayoutSubviews() { var layer = XFGlossGradientLayer.GetGradientLayer(this); if (layer != null) { layer.Frame = new CGRect(CGPoint.Empty, Frame.Size); } base.LayoutSubviews(); }
/// <summary> /// Updates the associated <see cref="T:XFGloss.iOS.Views.XFGlossGradientLayer"/> instance's steps collection. /// </summary> /// <param name="steps">The steps collection to assign</param> public void UpdateSteps(GradientStepCollection steps) { var layer = XFGlossGradientLayer.GetGradientLayer(this); layer?.UpdateSteps(steps); }
/// <summary> /// Updates the associated <see cref="T:XFGloss.iOS.Views.XFGlossGradientLayer"/> instance's rotation value. /// </summary> /// <param name="rotation">An integer number between 0 and 359</param> public void UpdateRotation(int rotation) { var layer = XFGlossGradientLayer.GetGradientLayer(this); layer?.UpdateRotation(rotation); }
/// <summary> /// Initializes a new instance of the <see cref="T:XFGloss.iOS.Views.UIBackgroundGradientView"/> class. /// </summary> /// <param name="rect">Rect.</param> /// <param name="gradientSource">Gradient source.</param> public UIBackgroundGradientView(CGRect rect, Gradient gradientSource) : base(rect) { XFGlossGradientLayer.CreateGradientLayer(this, gradientSource); }