public override void Draw(CGRect rect) { rect.X += _border / 2.0f; rect.Width -= _border; rect.Y += _border / 2.0f; rect.Height -= _border; CGContext cr = UIGraphics.GetCurrentContext(); float [] cornerRadii = new float[4]; if (_CornerRadii != null) { Array.Copy(_CornerRadii, cornerRadii, 4); } else { for (int i = 0; i < 4; i++) { cornerRadii[i] = CornerRadius; } } if (_gradient != null) { cr.DrawRoundRect(_gradient.Gradient, rect, cornerRadii); } else { cr.DrawRoundRect(GraphicUtils.CreateNormalGradient(_color1, _color2), rect, cornerRadii); } if (_border > 0) { GraphicUtils.RoundRectPath(cr, rect, cornerRadii); cr.SetStrokeColor(_borderColor.CGColor.Components); cr.SetLineWidth(_border); cr.StrokePath(); } }
public override void Draw(CGRect rect) { SetNeedsDisplay(); base.Draw(rect); rect.X += _border / 2.0f; rect.Width -= _border; rect.Y += _border / 2.0f; rect.Height -= _border; CGContext cr = UIGraphics.GetCurrentContext(); //cr.SetAllowsAntialiasing(true); float [] cornerRadii = new float[4]; if (_CornerRadii != null) { Array.Copy(_CornerRadii, cornerRadii, 4); } else if (_SkipCorners != null) { for (int i = 0; i < 4; i++) { cornerRadii[i] = _SkipCorners[i]?0f:CornerRadius; } } else { for (int i = 0; i < 4; i++) { cornerRadii[i] = CornerRadius; } } GradientHelper useGradient = _gradient; bool reversed = false; if (!Enabled && _DisabledGradient != null) { useGradient = _DisabledGradient; } else if (Highlighted && Tracking) { if (_HighlightedGradient == null) { reversed = true; } else { _gradient = _HighlightedGradient; } } cr.DrawRoundRect(useGradient.Gradient, rect, cornerRadii, reversed?(float)Math.PI / 2.0f:(float)-Math.PI / 2.0f); if (_border > 0) { if (_SkipCorners == null && _CornerRadii == null) { GraphicUtils.RoundRectPath(cr, rect, _cornerRadius); } else if (_SkipCorners != null) { GraphicUtils.RoundRectPath(cr, rect, _cornerRadius, _SkipCorners); } else if (_CornerRadii != null) { GraphicUtils.RoundRectPath(cr, rect, _CornerRadii); } cr.SetStrokeColor(_borderColor.CGColor.Components); cr.SetLineWidth(_border); cr.StrokePath(); } if (BonusImage != null) { cr.TranslateCTM(0, BonusImage.Size.Height + _BonusImageRect.Y * 2.0f); cr.ScaleCTM(1.0f, -1.0f); cr.DrawImage(_BonusImageRect, _BonusImage.CGImage); } }