iOS-柱状图
2015-09-09 19:38
211 查看
和饼图差不多,代码差别不大
// // HMPieView.m // 饼图 // // Created by YaguangZhu on 15/9/9. // Copyright (c) 2015年 YaguangZhu. All rights reserved. // #import "HMPieView.h" #import "UIColor+Random.h" @implementation HMPieView // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code NSArray *data = @[@25,@25,@50]; int count = data.count; CGFloat w = rect.size.width/(2*count -1); CGFloat h =0; CGFloat x =0; CGFloat y =0; CGFloat viewH = rect.size.height; CGContextRef ctx = UIGraphicsGetCurrentContext(); for (int i = 0 ; i< count; i++) { h = viewH * [data[i] intValue]/100.0; x= 2 * w * i; y= viewH - h; UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(x, y, w, h)]; CGContextAddPath(ctx, path.CGPath); [[UIColor randomColor]set]; CGContextFillPath(ctx); } } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self setNeedsDisplay]; } @end
相关文章推荐
- iOS开发之 面向对象的三大特征以及字符串的处理
- ios-音乐播放器(2)工具类的封装
- iOS开发之 字典和可变字典初解
- IOS学习之ios沙河机制
- iOS开发知识点装逼1:理解assign,copy,retain变strong
- iOS远程推送之使用极光推送
- iOS开发 之数组初解
- IOS之数据持久化(归档与反归档)
- IOS设置button 图片 文字 上下、左右
- iOS-runtime-根据协议名调某一个类有与协议里面放的相同的方法
- IOS-跳转到设置页
- iOS-饼图
- iOS block里的self
- IOS在后台每隔一段时间执行一下
- ios nil、NULL和NSNull 的使用
- iOS框架学习(一)
- iOS9 - ATS
- iOS开发~Cornerstone与Cocopods一起使用的问题
- iOS排错心得
- phoneGap+iOS环境搭建