Quartz2D - 画柱状图
2016-03-06 19:02
309 查看
// // BarView.m #import "BarView.h" @implementation BarView - (void)drawRect:(CGRect)rect { // 数据 NSArray *arr = @[@25,@25,@50]; //属性值 CGFloat x = 0; CGFloat y = 0; CGFloat w = 0; CGFloat h = 0; for (int i=0; i<arr.count; i++) { w = rect.size.width / (arr.count * 2 - 1); x = 2 * w * i; h = [arr[i] floatValue] / 100.0 * rect.size.height; y = rect.size.height - h; UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(x, y, w, h)]; [[self colorRandom] set]; [path fill]; } } /** * 随机一个颜色 */ - (UIColor *)colorRandom { CGFloat red = arc4random_uniform(256) / 255.0; CGFloat green = arc4random_uniform(256) / 255.0; CGFloat blue = arc4random_uniform(256) / 255.0; return [UIColor colorWithRed:red green:green blue:blue alpha:1.0]; } @end
相关文章推荐
- 函数
- BZOJ_P4415 [SHOI2013]发牌(线段树)
- Linux内核分析第二周:操作系统是如何工作的
- 为何要学习Java语言
- 用python实现基本A*算法
- 使用SHELL完成两个数字的大小比较
- 浅谈Android开发中内存泄露与优化
- 人生必get技
- spring 依赖注入四种方式
- mongodb3.2配置文件yaml格式
- hiho[Offer收割]编程练习赛1
- RecycleView出现折叠效果
- 关于Python编程的一些问答
- 省电续航-相互唤醒
- JVM之垃圾回收算法
- poj 2451:Uyuw's Concert
- JQuery选择器
- 校内欢乐赛之爆零季 POJ 1904
- 用户态事件
- 关于字符串参数传递的小技巧