前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >iOS 《Quartz 2D编程指南》之常见图形的绘制【 饼图、柱状图、雪花、手势密码、画板】

iOS 《Quartz 2D编程指南》之常见图形的绘制【 饼图、柱状图、雪花、手势密码、画板】

作者头像
公众号iOS逆向
发布2021-04-15 16:08:02
3440
发布2021-04-15 16:08:02
举报
文章被收录于专栏:iOS逆向与安全iOS逆向与安全

引言

原文:

https://kunnan.blog.csdn.net/article/details/113043866

I、 饼图

这里写图片描述

代码语言:javascript
复制
/*pie
 
 寻找规律
 
 */
 
// Only override drawRect: if you perform custom drawing.
 
// An empty implementation adversely affects performance during animation.
 
- (void)drawRect:(CGRect)rect {
 
    // Drawing code
 
    CGContextRef context = UIGraphicsGetCurrentContext();
 
    NSArray *data = @[@25,@25,@50];
 
    CGPoint center = CGPointMake(125, 125);
 
    CGFloat radious = 100;//半径
 
    CGFloat startAngle = 0;//起始弧度
 
    CGFloat endAngle = 0;
 
    CGFloat angle = 0;
 
    //开始绘制饼图
 
    for (NSNumber *num in data) {
 
        //绘制
 
        angle =num.floatValue/100.0 *M_PI*2;
 
        startAngle = endAngle;//上一个饼图的结束弧度为下一个饼图的开始弧度
 
        endAngle = startAngle + angle;
 
        UIBezierPath *path2 = [UIBezierPath bezierPathWithArcCenter:center radius:radious startAngle:startAngle endAngle:endAngle clockwise:YES];
 
        [path2 addLineToPoint:center];
 
        CGContextAddPath(context, path2.CGPath);
 
        [[UIColor randomColor]set];
 
        //渲染第i个
 
        CGContextFillPath(context);
 
    }
 
     
 
}
 
 
 
 
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
 
    [self setNeedsDisplay];
 
}
 
//生成随机颜色
+ (UIColor *)randomColor{
 
    /*
 
     RGB 24位,RGB 每个颜色通道8位,8 的二进制255,即颜色取值是0~255
 
     RGBA
 
     */
 
    CGFloat red = arc4random_uniform(256)/255.0;
 
    CGFloat blue = arc4random_uniform(256)/255.0;
 
    CGFloat green = arc4random_uniform(256)/255.0;
 
    return  [UIColor colorWithRed:red green:green blue:blue alpha:1];
 
}

II、柱状图

这里写图片描述

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2021-04-13,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 iOS逆向 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 引言
  • I、 饼图
  • II、柱状图
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档