2013-06-25 60 views
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); 
     } 
    } 

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); 

     } 
    } 
} 

回答

6

您可以清除与背景:

CGContextClearRect(context, rect); 

或设为白搭配:

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

还要确保您的自定义视图的背景颜色设置为'clear'。它默认为黑色,因此是一个额外的必需步骤。 –

0

使用此代码。

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

实现此code.Thanks