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 it's the current path
G.addpath (path);
Set the current path to being 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);
Run results
Graphics and Animation in IOS