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'。它默認爲黑色,因此是一個額外的必需步驟。 –