IOS第16天(4,Quartz2D柱状图)
2015-09-01 17:09
471 查看
***
#import "HMBarView.h" #import "UIColor+Random.h" @implementation HMBarView - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { // Initialization code } return self; } // 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; // 1.获取上下文 CGContextRef ctx = UIGraphicsGetCurrentContext(); for (int i = 0; i < count; i++) { h = viewH * [data[i] intValue] / 100.0; x = 2 * w * i; y = viewH - h; // 2.拼接路径 UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(x, y, w, h)]; // 3.添加路径到上下文 CGContextAddPath(ctx, path.CGPath); [[UIColor randomColor] set]; // 4.渲染 CGContextFillPath(ctx); } } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self setNeedsDisplay]; } @end
相关文章推荐
- IOS第16天(3,Quartz2D饼图)
- IOS第16天(2,Quartz2D下载进度条)
- 14.IOS中系统唯一标识ID
- iOS KVC,KVO
- 4.极光推送解释的iOS本地通知
- 5.iOS 7 Background Remote Notification
- 2.iOS苹果推送-一些示例代码和注意的问题
- 1.iOS中的系统通知 自定义推送声音
- IOS开发-视频,音频,录音简单总结
- iOS开发系列--音频播放、录音、视频播放、拍照、视频录制
- IOS中nil/Nil/NULL的区别
- iOS-Quartz2D绘图的基础用法总结
- iOS中socket的使用
- iOS 设置导航栏 Navigationbar相关信息
- IOS-添加分段控件SegmentControl
- IOS时间与日期处理
- iOS读取本地txt文件为乱码的解决方法
- iOS 软件中所有动画突然不能正常显示(系统自带的动画也成了一闪而过)
- ios 用NSUserDefaults做本地化搜索记录
- 苹果开发 笔记(68)MBProgressHUD