Graphics and Animation in iOS
using UIKit;
using CoreGraphics;
using Foundation;
namespace GraphicsAnimation
{
public class TriangleView : UIView
{
CGPath path;
public TriangleView ()
{
BackgroundColor = UIColor.White;
}
public override void Draw(CGRect rect)
{
base.Draw (rect);
using(var g=UIGraphics.GetCurrentContext()){
//set up drawing attributes
g.SetLineWidth(10);
UIColor.Blue.SetFill ();
//UIColor.Purple.SetFill ();
//UIColor.Black.SetStroke ();
UIColor.Red.SetStroke();
//create geometry
path = new CGPath ();
path.AddLines (new CGPoint[]{new CGPoint(100,200),new CGPoint(160,100),new CGPoint(220,200)});
path.CloseSubpath();
//use a dashed line
g.SetLineDash(0, new nfloat[]{10,4});
//add geometry to graphics context and draw it
g.AddPath(path);
g.DrawPath(CGPathDrawingMode.FillStroke);
// add the path back to the graphics context so that it is the current path
g.AddPath (path);
// set the current path to be the clipping path
g.Clip ();
using (CGColorSpace rgb = CGColorSpace.CreateDeviceRGB()) {
CGGradient gradient = new CGGradient (rgb, new CGColor[] {
UIColor.Blue.CGColor,
UIColor.Yellow.CGColor
});
// draw a linear gradient
g.DrawLinearGradient (
gradient,
new CGPoint (path.BoundingBox.Left, path.BoundingBox.Top),
new CGPoint (path.BoundingBox.Right, path.BoundingBox.Bottom),
CGGradientDrawingOptions.DrawsBeforeStartLocation);
}
}
}
}
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Perform any additional setup after loading the view, typically from a nib.
TriangleView triangleView=new TriangleView{Frame=UIScreen.MainScreen.Bounds};
View.AddSubview (triangleView);
}
最新文章
- MySQL入门03-MySQL配置安全性、易用性
- c++中函数中变量内存分配以及返回指针、引用类型的思考
- 自然语言18.1_Named Entity Recognition with NLTK
- RecycleView可以策划的Item
- 基于 MeanShift 算法的目标跟踪问题研究
- ubuntu笔记1
- Oracl 动态执行表不可访问,本会话的自动统计被禁止
- 解决Mac上Android开发时adb连接不到手机问题
- 一个用python实现的东方时尚(驾校)抢课程序
- Windows系统结构
- UVA 11525 Permutation(树状数组)
- Python tools used for file name devision
- Linux学习(一)
- linkin大话面向对象--多态
- poi横纵导出
- Xposed Hook &; Anti-hook
- day2-课堂笔记
- CS229笔记:生成学习算法
- Python基础教程-第3版(文字版) 超清文字-非扫描版 [免积分、免登录]
- angular2 文件上传