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

运行结果

 
 

Graphics and Animation in iOS的更多相关文章

  1. UIKit,Core Data , Core Graphics, Core Animation,和OpenGLES框架

    iOS的主要框架介绍   框架是一个目录,这个目录包含了共享库,访问共享库里代码的头文件,和其它的图片和声音的资源文件.一个共享库定义的方法或函数可以被应用程序调用. IOS提供了很多你可以在应用程序 ...

  2. (转) [it-ebooks]电子书列表

    [it-ebooks]电子书列表   [2014]: Learning Objective-C by Developing iPhone Games || Leverage Xcode and Obj ...

  3. Designing for iOS: Graphics & Performance

    http://robots.thoughtbot.com/designing-for-ios-graphics-performance  [原文] In the previous article, w ...

  4. iOS——Core Animation 知识摘抄(四)

    原文地址http://www.cocoachina.com/ios/20150106/10840.html 延迟解压 一旦图片文件被加载就必须要进行解码,解码过程是一个相当复杂的任务,需要消耗非常长的 ...

  5. iOS——Core Animation 知识摘抄(一)

    本文是对http://www.cocoachina.com/ios/20150104/10814.html文章的关键段落的摘抄,有需要的看原文 CALayer和UIView的关系: CALayer类在 ...

  6. [iOS Animation]-CALayer 性能优化

    性能优化 代码应该运行的尽量快,而不是更快 - 理查德 在第一和第二部分,我们了解了Core Animation提供的关于绘制和动画的一些特性.Core Animation功能和性能都非常强大,但如果 ...

  7. [iOS Animation]-CALayer 显示方式

    寄宿图 图片胜过千言万语,界面抵得上千图片 ——Ben Shneiderman 我们在第一章『图层树』中介绍了CALayer类并创建了一个简单的有蓝色背景的图层.背景颜色还好啦,但是如果它仅仅是展现了 ...

  8. IOS动画(Core Animation)总结 (参考多方文章)

    一.简介 iOS 动画主要是指Core Animation框架.官方使用文档地址为:Core Animation Guide. Core Animation是IOS和OS X平台上负责图形渲染与动画的 ...

  9. iOS 底层框架的浅析

    1.简介 IOS是由苹果公司为iPhone.iPod touch和iPad等设备开发的操作系统. 2.知识点 iPhone OS(现在叫iOS)是iPhone, iPod touch 和 iPad 设 ...

随机推荐

  1. jdk1.7升级到1.8遇到的问题

    1.修改project structure 里面的Project , Modules , SDKs jdk的版本 2.修改Java Compiler 里面java的jdk版本 3.tomcat 里面j ...

  2. DataSet的Merge方法合并两张表

    原文发布时间为:2008-08-01 -- 来源于本人的百度文章 [由搬家工具导入] UniqueConstraint uc = new UniqueConstraint("pk" ...

  3. Install Qualcomm Development Environment

    安裝 Android Development Environment http://www.cnblogs.com/youchihwang/p/6645880.html 除了上述還得安裝, sudo ...

  4. AC日记——线段树练习5 codevs 4927

    4927 线段树练习5  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 有n个数和5种操作 add a b ...

  5. html移动端 -- meta-模板 + rem

    第一种方式: ps 不用除以2<header> <meta charset="utf-8"> <meta name="viewport&qu ...

  6. Debian9安装MariaDB

    一:导入密钥并添加了存储库 sudo apt-get install software-properties-common dirmngr sudo apt-key adv --recv-keys - ...

  7. PV、PVC、StorageClass讲解

    PV.PVC.StorageClass讲解 为了方便开发人员更加容易的使用存储才出现的概念.通常我们在一个POD中定义使用存储是这样的方式,我们以hostpath类型来说: apiVersion: v ...

  8. 高并发场景下System.currentTimeMillis()的性能优化

    一.前言 System.currentTimeMillis()的调用比new一个普通对象要耗时的多(具体耗时高出多少我也不知道,不过听说在100倍左右),然而该方法又是一个常用方法, 有时不得不使用, ...

  9. 邁向IT專家成功之路的三十則鐵律 鐵律二十九 IT人富足之道-信仰

    天地自然的循環法則,讓每一個人都必須經歷生.老.病.死.喜.怒.哀.樂,然而至始至終無盡的煩惱總是遠多於快樂,因此筆者深信每一個人在一生當中,都必須要有適合自己的正確信仰,他可以在你無法以物質力量來解 ...

  10. DEV GridControl 常用属性 z

    1隐藏最上面的GroupPanel gridView1.OptionsView.ShowGroupPanel=false; 2.得到当前选定记录某字段的值 sValue=Table.Rows[grid ...