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;

      

    }

  • 相关阅读:
    MySQL Limit优化(转)
    MySQL数据库性能优化思路与解决方法(一转)
    Mysql占用CPU过高如何优化?(转)
    数据库方面两个简单实用的优化方法(转)
    硬盘扩容9999T
    python内涵段子爬取练习
    jmeter环境配置
    PyCharm3.0默认快捷键
    python3 操作页面上各种元素的方法
    python3 selenium webdriver 元素定位xpath定位骚操作
  • 原文地址:https://www.cnblogs.com/wujie123/p/6065423.html
Copyright © 2011-2022 走看看