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