码迷,mamicode.com
首页 > Windows程序 > 详细

Drawing Images and Text

时间:2015-05-06 22:33:43      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:

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);
}
运行结果:
技术分享

 

Drawing Images and Text

标签:

原文地址:http://www.cnblogs.com/bubugao/p/4483285.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!