美文网首页
MTBarChartView 画横线

MTBarChartView 画横线

作者: eb7a9dac29d0 | 来源:发表于2017-08-18 17:46 被阅读0次

    /*

    if (maxValue >0) {

    NSString *valueString = self.yLabelsOne[i];

    float value = [valueString floatValue];

    float grade = (float)value/ (float) _YValueMax;

    NSString *valueString2 = self.yLabelsTwo[i];

    float value2 = [valueString2 floatValue];

    float grade2 = (float)value2 / (float) _YValueMax;

    _bar3 = [[MTBarView alloc] initWithFrame:CGRectMake(UUYLabelwidth+i*_xLabelWidth - viewX(2), 0, viewX(22), chartCavanHeight)];

    _bar3.barColor3 = [UIColor colorWithHex:@"#3FAAF4"];

    //            _bar3.gradePercent3 = 0.041429;

    _bar3.gradePercent3 = 0.6414;

    _bar3.tag = i + 500;

    [self.myScrollView addSubview:_bar3];

    _bar = [[MTBarView alloc] initWithFrame:CGRectMake(UUYLabelwidth+i*_xLabelWidth - viewX(2), 0, viewX(22), chartCavanHeight)];

    _bar.barColor = self.barColor ? self.barColor :  [UIColor colorWithHex:@"#0FE87B"];

    //            if (grade > 0) {

    //                _bar.gradePercent = grade - 0.042;

    //            }else{

    //                _bar.gradePercent = grade;

    //            }

    if (grade > 0) {

    _bar.gradePercent = 0.7414;

    }else{

    _bar.gradePercent = 0.7414;

    }

    _bar.tag = i + 600;

    [self.myScrollView addSubview:_bar];

    _bar2 = [[MTBarView alloc] initWithFrame:CGRectMake(UUYLabelwidth+i*_xLabelWidth - viewX(2), 0, viewX(22), chartCavanHeight)];

    _bar2.barColor2 = [UIColor colorWithHex:@"#FFCF4D"];

    //            if (grade2 > 0) {

    //                _bar2.gradePercent2 = grade2 - 0.042;

    //            }else{

    //                _bar2.gradePercent2 = grade2;

    //            }

    if (grade2 > 0) {

    _bar2.gradePercent2 = 0.4414;

    }else{

    _bar2.gradePercent2 = 0.4414;

    }

    _bar2.tag = i + 700;

    [self.myScrollView addSubview:_bar2];

    }else{

    _bar3 = [[MTBarView alloc] initWithFrame:CGRectMake(UUYLabelwidth+i*_xLabelWidth - viewX(2), 0 , viewX(20), chartCavanHeight)];

    _bar3.barColor3 = [UIColor colorWithHex:@"#3FAAF4"];

    //            _bar3.gradePercent3 = 0.041429;

    _bar3.gradePercent3 = 0.6414;

    _bar3.tag = i + 500;

    [self.myScrollView addSubview:_bar3];

    }

    */

    CGFloat  start_X = xLabelMargin + UUYLabelwidth;

    CGFloat  start_Y = yLabelMargin / 2.0 + UULabelHeight;

    self.startPoint = CGPointMake(start_X, start_Y);

    //画横线

    for (int i=0; i<5; i++) {

    UIView * line = [[UIView alloc]initWithFrame:CGRectMake(viewX(20), chartCavanHeight - (i+1) * levelHeight + viewY(5), self.frame.size.width - viewX(20), viewY(1) )];

    line.backgroundColor = [UIColor colorWithHex:@"#E7EDF0"];

    [self.myScrollView addSubview:line];

    //实线

    CAShapeLayer *xLayer = [CAShapeLayer layer];

    UIBezierPath *xPath = [[UIBezierPath alloc] init];

    [xPath moveToPoint:CGPointMake(self.startPoint.x - viewX(20), chartCavanHeight - (i+1) * levelHeight + viewY(5))];

    [xPath addLineToPoint:CGPointMake(self.startPoint.x - viewX(20) + self.frame.size.width, chartCavanHeight - (i+1) * levelHeight + viewY(5))];

    xLayer.lineWidth = viewY(0.2);

    xLayer.strokeColor = [UIColor colorWithHex:@"E7EDF0"].CGColor;

    xLayer.path = xPath.CGPath;

    [self.myScrollView.layer addSublayer:xLayer];

    }

    相关文章

      网友评论

          本文标题:MTBarChartView 画横线

          本文链接:https://www.haomeiwen.com/subject/osgarxtx.html