iphone - UIView 绘制时的背景色

标签 iphone ios uiview xamarin.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);
        }
    }

enter image description here

编辑:我的 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);

        }
    }
}

最佳答案

您可以使用以下方法清除背景:

CGContextClearRect(context, rect);

或设置为白色:

CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
CGContextFillRect(context, rect);

关于iphone - UIView 绘制时的背景色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17306330/

相关文章:

ios - 使用 Parse iOS SDK 创建 PFAnonymousUser 时出错

iphone - 如何在 iPhone 上接收 UserDefaults DidChangeNotification

ios - 跟踪单击哪个 UIAlert 按钮以更改 UILabel

iphone - 如何在没有导航 Controller 的情况下创建多个 View ?

ios - 从 CoreData 获取后,单元格中的 UIView 显示错误的颜色

swift - 在 subview 中显示 View Controller

iphone - 消除录音轨道中当前播放的轨道声音

iphone - 收到推送通知时从 View 中选择一行

ios - 从照片库中选取图像

ios - UIView 中的 UIButton 在另外两个 UIView 后面对上面的 View 的触摸使用react