iOS开发(OC)——折线图的绘制(带动画)

  1. 新建一个DrawLine类继承UIView
  2. DrawLine.h代码
@property (nonatomic,strong)NSMutableArray *data;



@property (nonatomic, strong) CAShapeLayer *lineChartLayer;
@property (nonatomic, strong)UIBezierPath * path1;
/** 渐变背景视图 */
@property (nonatomic, strong) UIView *gradientBackgroundView;
/** 渐变图层 */
@property (nonatomic, strong) CAGradientLayer *gradientLayer;
/** 颜色数组 */
@property (nonatomic, strong) NSMutableArray *gradientLayerColors;



@property (nonatomic,assign)int ySpace;//y轴间隔
@property (nonatomic,assign)int yNum;//y轴的分点数
@property (nonatomic,assign)int xSpace;//x轴间隔
@property (nonatomic,assign)int xNum;//x轴的分点数
@property (nonatomic,strong)NSString *ytitle;//y轴标题
@property (nonatomic,strong)NSString *xtitle;//x轴标题
@property (nonatomic,assign)BOOL showNum;//显示数值

//建立坐标
-(void)initCoordinate;
//开始画图
-(void)beginDraw;

3.DrawLine.m代码

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        [self drawGradientBackgroundView];
    }
    return self;
}



-(void)initCoordinate
{
    //y轴
//    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(50, 15, 1, self.frame.size.height-60)];
//    view.backgroundColor=[UIColor lightGrayColor];
//    [self addSubview:view];

    UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(70, 10, 150, 21)];
    label.text=self.ytitle;
    label.font=[UIFont systemFontOfSize:12];
    label.textColor=[UIColor grayColor];
    [self addSubview:label];


    for(int i=self.yNum;i>0;i--){

        UIView *cutoffLine=[[UIView alloc] initWithFrame:CGRectMake(51, 15+(self.frame.size.height-60)/(self.yNum+1)*(self.yNum+1-i), self.frame.size.width-100, 1)];
        cutoffLine.backgroundColor=[UIColor colorWithRed:245/255.0 green:245/
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值