Graphics and Animation in IOS

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.