zoukankan      html  css  js  c++  java
  • Graphics and Animation in iOS

     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);
    }
    运行结果
     
     
  • 相关阅读:
    python使用zipfile递归压缩和解压缩文件
    文件上传控件bootstrap-fileinput中文设置没有效果的情况
    vue keep-alive 不生效和多级(三级以上)缓存失败
    Entityframework批量删除
    EasyUI ComboGrid 集成分页、按键示例
    在Entity Framework中使用事务
    MVC实用构架设计(三)——EF-Code First(6):数据更新最佳实践
    Entityframework更新数据和插入数据
    esayui-datagrid的使用
    javascript:;与javascript:void(0)使用介绍
  • 原文地址:https://www.cnblogs.com/bubugao/p/4483111.html
Copyright © 2011-2022 走看看