Drawing a curve chart for ios

Source: Internet
Author: User

Drawing a curve chart for ios

-(Void) drawLine {// view is the curve background view UIView * view = [[UIView alloc] initWithFrame: CGRectMake (10, 0,300,300)]; view. backgroundColor = [UIColor whiteColor]; [self. view addSubview: view]; // first, UIBezierPath draws a line segment UIBezierPath * path = [UIBezierPath bezierPath]; // four points CGPoint point = CGPointMake (10, 10 ); CGPoint point1 = CGPointMake (200,100); CGPoint point2 = CGPointMake (240,200); CGPoint point3 = CGPointMake (290,200); NSArray * arr = [NSArray arrayWithObjects: [NSValue valueWithCGPoint: point] [NSValue identifier: point1], [NSValue valueWithCGPoint: point2], [NSValue valueWithCGPoint: point3], nil]; NSIndexSet * set = [NSIndexSet identifier: NSMakeRange (0, arr. count)];
// Second, draw this sentence
[Arr enumerateObjectsAtIndexes: set options: 0 usingBlock: ^ (NSValue * pointValue, NSUInteger idx, BOOL * stop) {CGPoint point = [pointValue CGPointValue]; [path addLineToPoint: point]; // (1) rect line drawing CGRect rect; rect. origin. x = point. *-1.5; rect. origin. y = point. y-1.5; rect. size. width = 4; rect. size. height = 4; // (2) rect Ray painting // CGRect rect = CGRectMake (10, 10, 1, 1); UIBezierPath * arc = [UIBezierPath bezierPathWithOvalInRect: rect]; [path appendPath: arc];}]; // third, UIBezierPath and CAShapeLayer are associated with CAShapeLayer * lineLayer = [CAShapeLayer layer]; lineLayer. frame = CGRectMake (0,150,320,400); lineLayer. fillColor = [UIColor redColor]. CGColor; lineLayer. path = path. CGPath; lineLayer. strokeColor = [UIColor redColor]. CGColor; [view. layer addSublayer: lineLayer]; // the following code is appended. // (1) it is opened like a canvas and appears to have an animated UIView * view1 = [[UIView alloc] initWithFrame: CGRectMake (0,100,320,400)]; view1.backgroundColor = [UIColor whiteColor]; [self. view addSubview: view1]; [UIView animateWithDuration: 5 Animation: ^ {view1.frame = CGRectMake (320,100,320,400);}];}


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.