UIView绘图时的背景颜色

Ian*_*ink 2 iphone uiview xamarin.ios ios xamarin

Objective-C或C#.Net答案很好

我有一个UIView,我在其中绘制文本.背景是黑色.如何将其设为白色或透明

    public override void Draw(RectangleF rect)
    {   
        using (var context = UIGraphics.GetCurrentContext())
        {
            context.ScaleCTM(1f,-1f);
            context.SetFillColor(Settings.ColorButtonText.CGColor);
            context.SetTextDrawingMode(CGTextDrawingMode.Fill);
            context.SelectFont("HelveticaNeue-Bold",20f, CGTextEncoding.MacRoman);
            context.ShowTextAtPoint(5,-25,_title);
        }
    }
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

编辑:我的Monotouch.Dialog自定义部分的解决方案

public class BigBlueSectionHeaderView : UIView
{
    private readonly string _title;

    public BigBlueSectionHeaderView(string title): base(new RectangleF(0,0,320,35))
    {
        _title = title;
    }

    public override void Draw(RectangleF rect)
    {   
        using (var context = UIGraphics.GetCurrentContext())
        {
            context.SetFillColorWithColor(UIColor.White.CGColor);
            context.FillRect(new RectangleF(10, 0, 320, 35));
            context.ScaleCTM(1f,-1f);
            context.SetFillColor(Settings.ColorButtonText.CGColor);
            context.SetTextDrawingMode(CGTextDrawingMode.Fill);
            context.SelectFont("HelveticaNeue-Bold",20f, CGTextEncoding.MacRoman);
            context.ShowTextAtPoint(5,-25,_title);

        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Wai*_*ain 7

您可以清除背景:

CGContextClearRect(context, rect);
Run Code Online (Sandbox Code Playgroud)

或设置为白色:

CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
CGContextFillRect(context, rect);
Run Code Online (Sandbox Code Playgroud)