Forum Xamarin.iOS

Drawing a transparent string in a UIView with Core Graphics

Stefan_StefanovStefan_Stefanov NLMember ✭✭
edited April 2016 in Xamarin.iOS

Hey guys,

I am trying to implement a UIView with a see through text using the CoreGraphics and more specifically the Draw() method. This is how my code looks like:

public override void Draw (CGRect rect)
    base.Draw (rect);

    var gctx = UIGraphics.GetCurrentContext ();

    gctx.AddEllipseInRect(new CGRect(rect.Location,rect.Size));
    gctx.SetFillColor (UIColor.FromRGB(217,234,251).CGColor);
    this.drawSubstractedText ((NSString)circleTime.Text, rect, gctx);

public void drawSubstractedText(NSString text, CGRect inRect, CGContext context)
    context.SaveState ();
    context.SetBlendMode (CGBlendMode.DestinationOut);
    context.TranslateCTM (circleTime.Frame.X,circleTime.Frame.Y);
    circleTime.Layer.DrawInContext (context);
    context.RestoreState ();

The code for drawing the ellipse is working but the drawSubstractedText() method doesn't seem to work.

Thanks in advance!

Sign In or Register to comment.