zoukankan      html  css  js  c++  java
  • 贝赛尔曲线 绘制园

    自定义view

    .h

    @interface MSProgressView : UIView

    @property (nonatomic, assign) CGFloat progress;

    @end

     

    .m

    - (void)setProgress:(CGFloat)progress

    {

        _progress = progress;

        self.label.text = [NSString stringWithFormat:@"%.2f%%",progress*100];

        

        //调用重绘方法drawRect

        [self setNeedsDisplay];

    }

    //视图第一次显示的时候自动调用调用

    //[self setNeedsDisplay]手动调用重绘方法drawRect

    - (void)drawRect:(CGRect)rect {

        

        //绘制的中心点

        CGPoint center = CGPointMake(rect.size.width*0.5, rect.size.height*0.5);

        //绘制的半径

        CGFloat radius = rect.size.width*0.5-5;

        //开始绘制角度

        CGFloat startAngle = -M_PI_2;

        //结束的绘制角度

        CGFloat endAngle = startAngle+M_PI*2*self.progress;

     

        //贝赛尔曲线

        //clockwise 是否顺时针  yes 顺时针   no 逆时针

        UIBezierPath *path =

        [UIBezierPath bezierPathWithArcCenter:center

                                       radius:radius

                                   startAngle:startAngle

                                     endAngle:endAngle

                                    clockwise:YES];

        //设置线宽

        [path setLineWidth:5];

        //设置中间填充色

        [[UIColor redColor] setFill];

        //设置幅度线颜色

        [[UIColor blackColor] setStroke];

        //开始绘制

        [path stroke];

        //开始绘制填充

        [path fill];

        

    }

     

    在控制器中 在storyboard中拖一个slider进度条

    - (IBAction)download:(UISlider *)sender {

        NSLog(@"progress = %f",sender.value);

        self.progressView.progress = sender.value;

      

    }

  • 相关阅读:
    Java中“==”与equals的区别以及equals方法的重写
    Java中的Switch....case语句:
    Java中的基本数据类型
    HTTP与HTTPS的区别
    深入理解HTTP协议、HTTP协议原理分析
    IntelliJ IDEA下的使用git
    Spring RestTemplate详解
    Java 适配器(Adapter)模式
    LINUX的ssh免密码配置
    CDH6.2安装配置第一篇:CDH配置本地http服务
  • 原文地址:https://www.cnblogs.com/wujie123/p/6065423.html
Copyright © 2011-2022 走看看