Drawing Images and Text

using System;
using UIKit;
using Foundation;
using CoreGraphics;
namespace GraphicsAnimation
{
public class DrawnImageView : UIView
{
public DrawnImageView ()
{
BackgroundColor = UIColor.White;
}
public override void Draw(CGRect rect)
{
base.Draw (rect);
using(var g=UIGraphics.GetCurrentContext())
{
g.ScaleCTM (1,-1);//画出来的图像默认是倒立的
g.TranslateCTM (0,-Bounds.Height);
g.DrawImage (rect,UIImage.FromFile("MyImage.png").CGImage);
float fontSize = 35f;
g.TranslateCTM (0,fontSize);
g.SetLineWidth (1.0f);
g.SetStrokeColor (UIColor.Yellow.CGColor);
g.SetFillColor (UIColor.Red.CGColor);
//g.SetShadow (new SizeF (5, 5), 0, UIColor.Blue.CGColor);
g.SetShadow(new CGSize(5,5),0,UIColor.Blue.CGColor);
g.SetTextDrawingMode (CGTextDrawingMode.FillStroke);
g.SelectFont ("Helvetica", fontSize, CGTextEncoding.MacRoman);

// show the text
g.ShowText ("Hello Core Graphics");

}
}
}
}

————————————————

 #region View lifecycle

public override void ViewDidLoad ()
{
base.ViewDidLoad ();


DrawnImageView drawnImageView = new DrawnImageView { Frame=UIScreen.MainScreen.Bounds};
View.AddSubview (drawnImageView);
}
运行结果:

 

posted @ 2015-05-06 21:33  成败在我手  阅读(166)  评论(0编辑  收藏  举报