iOS 自定义柱状图

来源:互联网 发布:北航网络教育好毕业吗? 编辑:程序博客网 时间:2024/06/13 07:11

源代码

#import "ViewController.h"@interface ViewController ()@property (nonatomic,strong)CAShapeLayer *shapeLayer;@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    //创建出CAShapeLayer        CAShapeLayer *shapeLayer= [CAShapeLayer layer];        //self.shapeLayer.frame = self.view.frame;//设置shapeLayer的尺寸和位置        shapeLayer.fillColor= [UIColor clearColor].CGColor;//填充颜色为ClearColor        //设置线条的宽度和颜色        shapeLayer.lineWidth=30.0f;        shapeLayer.strokeColor= [UIColor greenColor].CGColor;        //创建出贝塞尔曲线        UIBezierPath*circlePath = [UIBezierPath bezierPath];        [circlePath moveToPoint:CGPointMake(100,200)];        [circlePath addLineToPoint:CGPointMake(100,100)];        //让贝塞尔曲线与CAShapeLayer产生联系        shapeLayer.path= circlePath.CGPath;        //添加并显示        [self.view.layer addSublayer:shapeLayer];        // Do any additional setup after loading the view.        CABasicAnimation*pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];        pathAnimation.duration=1.0f;        pathAnimation.timingFunction= [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];        pathAnimation.fromValue=@0.0f;        pathAnimation.toValue=@(1);        [shapeLayer addAnimation:pathAnimation forKey:@"strokeEndAnimation"];}

效果如下,通过for循环可以创建自定义柱状图


0 0
原创粉丝点击