iOS 自定义柱状图

2017-04-21 11:38:58来源:CSDN作者:bitcser人点击

源代码

#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循环可以创建自定义柱状图


最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台