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. Problem 2111 Min Number

                                                                                                        ...

  2. 清澄 A1485. Catch The Penguins 抓企鹅

    试题来源 2013中国国家集训队论文答辩 问题描述 Xyz带着他的教徒们乘着科考船一路破冰来到了南极大陆,发现这里有许许多多的企鹅.邪恶的Xyz想要抓很多企鹅回去开动物园,当宠物玩.但动物保护协会很快 ...

  3. 【CF721C】Journey(拓扑排序,最短路,DP)

    题意:给一个无环的图,问用不超过T的时间从1到n最多可以经过多少个点.要求输出一条路径. 思路:因为无环,可以用DP做.不过因为时间最短的原因要拓扑排序后再DP,目测由底向上的更新也是可以的. ; . ...

  4. 字蛛(font-spider)-单独压缩字体(解决页面少有的特殊字体的字体包引用)

    特别想独立的把这个问题写成一篇内容,分享给大家. 反正我是这个字体压缩使用的受益者,不是打广告. 很久以前,设计师总是爱用一些奇奇怪怪的字体放在页面上,而作为前端我们很容易的就能直接使用TA们用到的字 ...

  5. js-利用插件qrcode.min.js,前端实时生成二维码

    qrcode.min.js <script type="text/javascript" src="js/jquery.min.js"></s ...

  6. formValidator阻止提交跳转

    formValidator这个前台校验插件非常好用,其中有几个很有特点的方法可以单独提出使用,效果非常棒这里要说的是其核心方法之一,阻止提交动作,先校验,校验成功再执行提交动作 $("#ph ...

  7. UVA 10635 Prince and Princess【LCS 问题转换为 LIS】

    题目链接: http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=19051 题意: 有两个长度分别为p+1和q+1的由1到n2 ...

  8. Java创建和解析Json数据方法(四)——json-lib包的使用

    (四)json-lib包的使用         既然json-lib包比org.json包重量级,那么json-lib包肯定有很多org.json包没有的类和方法,这篇笔记简单记录json-lib包中 ...

  9. JSP页面顶端出现错误:The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path的问题解决

    原理:把RunTime容器添加进去,比如tomcat的. 1.项目右键->[Build Path]->[Configure Build Path...] 2.把tomcat的runtime ...

  10. 投资人王刚口述:滴滴如何用八十万成为百亿美金公司? zz

    作者|李好福布斯杂志中文版采编 阿里巴巴前高管.滴滴打车天使投资人王刚近日在杭州接受了<福布斯>独家专访,讲述了集齐“阿里的人.百度的技术.腾讯的钱”的滴滴如何从八十万启动资金,在三年内成 ...