using System;
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);
}

}
}
}
}

——————————————————————————————
 #region View lifecycle

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);
}

运行结果

 
 

最新文章

  1. MySQL入门03-MySQL配置安全性、易用性
  2. c++中函数中变量内存分配以及返回指针、引用类型的思考
  3. 自然语言18.1_Named Entity Recognition with NLTK
  4. RecycleView可以策划的Item
  5. 基于 MeanShift 算法的目标跟踪问题研究
  6. ubuntu笔记1
  7. Oracl 动态执行表不可访问,本会话的自动统计被禁止
  8. 解决Mac上Android开发时adb连接不到手机问题
  9. 一个用python实现的东方时尚(驾校)抢课程序
  10. Windows系统结构
  11. UVA 11525 Permutation(树状数组)
  12. Python tools used for file name devision
  13. Linux学习(一)
  14. linkin大话面向对象--多态
  15. poi横纵导出
  16. Xposed Hook & Anti-hook
  17. day2-课堂笔记
  18. CS229笔记:生成学习算法
  19. Python基础教程-第3版(文字版) 超清文字-非扫描版 [免积分、免登录]
  20. angular2 文件上传

热门文章

  1. bzoj 1069 凸包+旋转卡壳
  2. jump 转换进制+dp
  3. 一简单c++程序之反汇编
  4. git add 错误修改方法
  5. (2).net core2.1 Startup.cs
  6. 透明代理Transparent Proxy
  7. Codeforces Gym 100203G Good elements 暴力乱搞
  8. 【IOI2014】Game
  9. JavaScript实现弹幕效果
  10. Spring Boot中使用AOP记录请求日志