Objective-C or C# .Net answers fine
I have a UIView in which I draw text. The background is Black . How do I make it White or Clear ?
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);
}
}
EDIT : My Solution for a Custom Section for 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);
}
}
}
You can clear the background with:
CGContextClearRect(context, rect);
Or set to white with:
CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
CGContextFillRect(context, rect);
Use this code .
CGContextClearRect(context, rect);
CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
CGContextFillRect(context, rect);
This is implemented code.Thanks
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.