2
的Objective-C或C#.NET答案精UIView的背景颜色绘制
时,我有一个的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);
}
}
}
还要确保您的自定义视图的背景颜色设置为'clear'。它默认为黑色,因此是一个额外的必需步骤。 –