股票折线图demo(兼容SDK7编译,ios7)
来源:互联网 发布:37龙神契约进阶数据库 编辑:程序博客网 时间:2024/06/05 04:54
https://github.com/easyui/StockPlotting
//// SPView.m// StockPlotting//// Created by EZ on 13-11-5.// Copyright (c) 2013年 cactus. All rights reserved.//#define NLSystemVersionGreaterOrEqualThan(version) ([[[UIDevice currentDevice] systemVersion] floatValue] >= version)#define IOS7_OR_LATER NLSystemVersionGreaterOrEqualThan(7.0)#define GraphColor [[UIColor greenColor] colorWithAlphaComponent:0.5]#define str(index) [NSString stringWithFormat : @"%.f", [[self.values objectAtIndex:(index)] floatValue] * kYScale]#define point(x, y) CGPointMake((x) * kXScale, yOffset + (y) * kYScale)#import "SPView.h"@interface SPView ()@property (nonatomic, strong) dispatch_source_t timer;@end@implementation SPViewconst CGFloat kXScale = 15.0;const CGFloat kYScale = 50.0;static inline CGAffineTransformCGAffineTransformMakeScaleTranslate(CGFloat sx, CGFloat sy, CGFloat dx, CGFloat dy){ return CGAffineTransformMake(sx, 0.f, 0.f, sy, dx, dy);}- (id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { // Initialization code } return self;}- (void)awakeFromNib{ [self setContentMode:UIViewContentModeRight]; _values = [NSMutableArray array]; __weak id weakSelf = self; double delayInSeconds = 0.25; self.timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_main_queue()); dispatch_source_set_timer( _timer, dispatch_walltime(NULL, 0), (unsigned)(delayInSeconds * NSEC_PER_SEC), 0); dispatch_source_set_event_handler(_timer, ^{ [weakSelf updateValues]; }); dispatch_resume(_timer);}- (void)updateValues{ double nextValue = sin(CFAbsoluteTimeGetCurrent()) + ((double)rand() / (double)RAND_MAX); [self.values addObject: [NSNumber numberWithDouble:nextValue]]; CGSize size = self.bounds.size; /* * UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; * if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight){ * * * } */ CGFloat maxDimension = size.width; // MAX(size.height, size.width); NSUInteger maxValues = (NSUInteger)floorl(maxDimension / kXScale); if ([self.values count] > maxValues) { [self.values removeObjectsInRange: NSMakeRange(0, [self.values count] - maxValues)]; } [self setNeedsDisplay];}- (void)dealloc{ dispatch_source_cancel(_timer);}- (void)drawRect:(CGRect)rect{ if ([self.values count] == 0) { return; } CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextSetStrokeColorWithColor(ctx, [GraphColor CGColor]); CGContextSetLineJoin(ctx, kCGLineJoinRound); CGContextSetLineWidth(ctx, 2); CGMutablePathRef path = CGPathCreateMutable(); CGFloat yOffset = self.bounds.size.height / 2; CGAffineTransform transform = CGAffineTransformMakeScaleTranslate(kXScale, kYScale, 0, yOffset); CGPathMoveToPoint(path, &transform, 0, 0); CGPathAddLineToPoint(path, &transform, self.bounds.size.width, 0); // self.bounds.size.width其实大了kXScale倍 CGFloat y = [[self.values objectAtIndex:0] floatValue]; CGPathMoveToPoint(path, &transform, 0, y); [self drawAtPoint:point(0, y) withStr:str(0)]; for (NSUInteger x = 1; x < [self.values count]; ++x) { y = [[self.values objectAtIndex:x] floatValue]; CGPathAddLineToPoint(path, &transform, x, y); [self drawAtPoint:point(x, y) withStr:str(x)]; } CGContextAddPath(ctx, path); CGPathRelease(path); CGContextStrokePath(ctx);}- (void)drawAtPoint:(CGPoint)point withStr:(NSString *)str{ if (IOS7_OR_LATER) { #if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1 [str drawAtPoint:point withAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:8], NSStrokeColorAttributeName:GraphColor}]; #endif } else { [str drawAtPoint:point withFont:[UIFont systemFontOfSize:8]]; } }@end
阅读全文
0 0
- 股票折线图demo(兼容SDK7编译,ios7)
- 兼容sdk7&iOS7的issue解决小片段总结
- 兼容sdk7&iOS7的issue解决小片段总结
- 兼容sdk7&iOS7的issue解决小片段总结
- 兼容sdk7&iOS7的issue解决小片段总结
- 兼容SDK7&iOS7的issue解决小片段总结
- 兼容sdk7&iOS7的issue解决小片段总结
- 兼容sdk7&iOS7的issue解决小片段总结
- 兼容sdk7&iOS7的issue解决小片段总结
- 防股票折线图十字定位(achartengine)
- Xcode5--sdk7.1-----编译ffmpeg
- ios7兼容
- K线图控件,类似于苹果手机股票折线图
- echart统计图表折线图demo
- echarts动态加载折线图数据demo
- echarts动态加载折线图数据demo
- IOS7 兼容适配总结(一)
- IOS7 兼容适配总结(一)
- Ubuntu中vi命令使用
- CGAffineTransformMake(a,b,c,d,tx,ty) 矩阵运算的原理
- 精通Dubbo——dubbo2.0源码中Spring Bean的加载
- UIImage的imageOrientation属性(app中图片旋转了的bug)
- CodeVS 2924 数独挑战 题解
- 股票折线图demo(兼容SDK7编译,ios7)
- iOS5&iOS6 Grouped类型UITableView背景色设置问题
- easyui-combotree实现树形结构的下拉控件,并实现节点回显
- 文本框的设置
- ios 设置屏幕方向的两种方法
- 牛客网_华为机试_009_提取不重复的整数
- Jave调用JaveScript
- IOS6屏幕旋转详解(自动旋转、手动旋转、兼容IOS6之前系统)
- 根据指定的保留小数位进行四舍五入