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);
}
}
}
最佳答案
您可以使用以下方法清除背景:
CGContextClearRect(context, rect);
或设置为白色:
CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
CGContextFillRect(context, rect);
关于iphone - UIView 绘制时的背景色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17306330/