- 浏览: 162348 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
xxdxuxiangdong:
org.springframework.security.ui ...
spring-security 帮助文档中整理出来的简单记录摘要 -
许傻子:
怎么看不到东西哦
一个javascript的格式化工具 -
zouwu85:
根本就不行
java 屏幕录制 -
mislay:
pixelmator
iPhone 突然发现,setting配置文件中的DefaultValue可能拿不了值 -
sharewind:
请教一下你这截图用的工具是啥来着
iPhone 突然发现,setting配置文件中的DefaultValue可能拿不了值
说实话,OC代码写着真的很别扭,速度明显慢N倍.
下面是一个简单的line chart,虽然很难看,但是好歹照虎画猫也能弄个模子出来...
#define AXIS_Y_ITEM_COUNT 5 #define AXIS_X_ITEM_COUNT 5 NSMutableArray* radom_data() { srand((unsigned)time(NULL)); float base = 30; NSMutableArray *array = [[NSMutableArray alloc] init]; for (int i = 0; i < 100; i++) { NSLog(@"%f", (rand() % 1000) / 100.f + base); [array addObject:[NSNumber numberWithFloat:((rand() % 1000) / 100.f + base)]]; } return array; } float _max(NSArray *data) { float max = [[data objectAtIndex:0] floatValue]; for(NSNumber* num in data) { max = [num floatValue] > max ? [num floatValue] : max; } return max; } float _min(NSArray *data) { float min = [[data objectAtIndex:0] floatValue]; for(NSNumber* num in data) { min = [num floatValue] < min ? [num floatValue] : min; } return min; } - (id)initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) { viewFrame = frame; } return self; } - (void)drawRect:(CGRect)rect { NSLog(@"######################## %f %f", viewFrame.size.width, viewFrame.size.height); NSNumberFormatter *numberFormatter = [NSNumberFormatter new]; [numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle]; [numberFormatter setMinimumFractionDigits:2]; [numberFormatter setMaximumFractionDigits:2]; NSMutableArray* data = radom_data(); float max = _max(data); float min = _min(data); float offsetWidth = 80.0f; // 50 * 2 + 10 * 2 float offsetHeight = 60.0f; // 20 * 2 + 10 * 2 float stepY = (max - min) / AXIS_Y_ITEM_COUNT; float axisY_step = (viewFrame.size.height - offsetHeight) / (max - min); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextClearRect(context, rect); for (int i = 0; i < AXIS_Y_ITEM_COUNT + 1; i++) { CGFloat lineDash[2]; lineDash[0] = 10.0f; lineDash[1] = 15.0f; CGContextSetLineDash(context, 0.0f, lineDash, 2); CGContextSetLineWidth(context, 0.6f); CGPoint sPoint = CGPointMake(offsetWidth / 2, viewFrame.size.height - (offsetHeight / 2) - i * stepY * axisY_step); CGPoint ePoint = CGPointMake(viewFrame.size.width - offsetWidth / 2, viewFrame.size.height - (offsetHeight / 2) - i * stepY * axisY_step); CGContextMoveToPoint(context, sPoint.x, sPoint.y); CGContextAddLineToPoint(context, ePoint.x, ePoint.y); CGContextClosePath(context); CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor); CGContextStrokePath(context); UIFont *axisFont = [UIFont systemFontOfSize:[UIFont smallSystemFontSize]]; NSNumber *axisValue = [NSNumber numberWithFloat:(min + i * stepY)]; CGRect axisRect = CGRectMake(0.0f, sPoint.y - axisFont.capHeight, 50.0f, 20.0f); //CGRect axisRect = CGRectMake(0.0f, sPoint.y, 50.0f, 20.0f); [[UIColor redColor] set]; NSLog(@"%@", [numberFormatter stringForObjectValue:axisFont]); [[numberFormatter stringForObjectValue:axisValue] drawInRect:axisRect withFont:axisFont lineBreakMode:UILineBreakModeTailTruncation alignment:UITextAlignmentLeft]; } float stepX = 100 / AXIS_X_ITEM_COUNT; float axisX_step = (viewFrame.size.width - offsetWidth) / 100; CGContextSetLineDash(context, 0.0f, NULL, 0); for(int i = 0; i < AXIS_X_ITEM_COUNT + 1; i++) { CGPoint sPoint = CGPointMake(offsetWidth / 2 + i * stepX * axisX_step, viewFrame.size.height - offsetHeight / 2); CGContextMoveToPoint(context, sPoint.x, viewFrame.size.height - offsetHeight / 2); CGContextAddLineToPoint(context, sPoint.x, viewFrame.size.height - offsetHeight / 2 + 10); CGContextClosePath(context); CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor); CGContextStrokePath(context); CGRect axisRect = CGRectMake(sPoint.x - 50 / 2, viewFrame.size.height - 20, 50.0f, 20.0f); UIFont *axisFont = [UIFont systemFontOfSize:[UIFont smallSystemFontSize]]; NSNumber *axisValue = [NSNumber numberWithInt:(i * stepX)]; NSLog(@"%f %f %@", axisRect.origin.x, axisRect.origin.y, [axisValue stringValue]); [[UIColor yellowColor] set]; [[axisValue stringValue] drawInRect:axisRect withFont:axisFont lineBreakMode:UILineBreakModeTailTruncation alignment:UITextAlignmentCenter]; } /* CGContextSetLineDash(context, 0.0f, NULL, 0); CGContextMoveToPoint(context, offsetWidth / 2, 0.0); CGContextAddLineToPoint(context, offsetWidth / 2, viewFrame.size.height - offsetHeight / 2 + 10); CGContextClosePath(context); CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor); CGContextStrokePath(context); */ int _x = 0; for (NSNumber *number in data) { float value = [number floatValue]; CGPoint point = CGPointMake(_x++ * axisX_step + offsetWidth / 2, viewFrame.size.height - offsetHeight / 2 - (value - min) * axisY_step); if(_x == 1) { CGContextMoveToPoint(context, point.x, point.y); } else { CGContextAddLineToPoint(context, point.x, point.y); } } //CGContextSetLineCap(context, kCGLineCapRound); //CGContextSetLineJoin(context, kCGLineJoinRound); CGContextSetStrokeColorWithColor(context, [UIColor cyanColor].CGColor); CGContextStrokePath(context); } - (void)dealloc { [super dealloc]; } @synthesize viewFrame;
发表评论
-
模拟HUD, 就是那种loading等待的对话框框
2010-09-26 17:07 1690这个是网上抄袭的,改了改: #import &l ... -
那种类似toolbar可以提拖动的
2010-09-26 16:40 2401最开始, 是想利用toolBar来着,可惜好多原因(忘了?好像 ... -
画线性渐变的条条
2010-09-26 16:12 5091代码如下: CGGradientRef buildCG ... -
如果你发现图片在真机中无法看见
2010-09-25 18:23 997看看代码中是否少了图片的后缀名,如果少了,模拟器是正常执行的, ... -
iPhone 后台模式的流程图
2010-09-25 18:21 1331要闪人了,今天清理电脑发现了还有这样一张关于后台模式的流程图。 ... -
xCode 设置SVN的问题
2010-08-19 17:23 1621在网上搜了下,确实只能用如下步骤来进行: 1) ... -
iPhone 利用CG API画一个饼图(Pie chart)
2010-08-12 21:59 3266核心函数是:CGContextAddArc(CGContext ... -
iPhone Core Graphics 和 Quartz的关系
2010-08-12 00:05 3145quartz属于core graphic framewo ... -
iPhone 突然发现,setting配置文件中的DefaultValue可能拿不了值
2010-08-10 21:32 2546按照我的想法,如果用户没有在setting设置值且有defau ... -
iPhone iOS4升级后导致的BASE SDK MISSING
2010-08-10 13:42 3922今天升级到iOS4, xCode也升级到3.2.3, 但 ... -
iPhone WebView中掉用Javascript
2010-08-09 22:43 2158[webView stringByEvaluatingJava ... -
iPhone 在app中掉用Safari打开一个url
2010-08-07 16:03 1559[[UIApplication sharedApplic ... -
iPhone 利用系统播放音频文件
2010-08-03 22:24 1148系统音频播放的格式很少,而且不支持太大的音频文件,但是它是最简 ... -
iPhone 和输入,键盘相关的属性
2010-08-02 23:02 2991当文本输入时, 文本框有几中选择用于辅助输入: tex ... -
iPhone 画圆角矩形
2010-08-02 00:31 2275@implementation BrightnessCo ... -
iPhone NavigationBar和UIToolbar基础
2010-08-01 23:41 5132navigation bar 分为三个部分,左按钮,右按钮和中 ... -
iPhone 简单手势的判断
2010-07-31 23:36 2324不知道4.0SDK带有手势的直接支持没有,至少3.2已经可以用 ... -
iPhone 简单动画过度
2010-07-29 22:44 9520在iPhone中动画过度非常简单. 首先获取当前的图形 ... -
iPhone 触摸时UITouch的常用方法及属性
2010-07-29 00:31 5779再UIView中,可以重些以下四个方法来来控制用户的触摸动作: ... -
iPhone 简单的重画
2010-07-28 21:07 2228在UIView中,重写drawRect: (CGRect) a ...
相关推荐
用objective C写的实现iPhone上的Pie Chart,Line Chart and Bar Chart的显示和选中,虽不很完美,但比起很多简单的Demo,功能要完善很多。
来源:github/ios-linechartLicence:MIT平台:iOS设备:iPhone / iPad作者:Marcel Ruegenberg 效果很不错的曲线图,可以绘制坐标轴,并且可以在曲线图上标注小圆点。手指在曲线图上滑动时,小圆点上还会出现...
iphone X iphone 8 原型框 iphone X iphone 8 原型框
iPhone狂:约会iPhone
Iphone开发系列源码——Iphone主题源码Iphone开发系列源码——Iphone主题源码Iphone开发系列源码——Iphone主题源码Iphone开发系列源码——Iphone主题源码Iphone开发系列源码——Iphone主题源码Iphone开发系列源码...
iphoneos-arm iPhone 必备工具
Iphone开发系列源码——iPhone版Wordpress源代码Iphone开发系列源码——iPhone版Wordpress源代码Iphone开发系列源码——iPhone版Wordpress源代码Iphone开发系列源码——iPhone版Wordpress源代码Iphone开发系列源码...
iphone3,1 shsh iphone4 5.1.1iphone3,1 shsh iphone4 5.1.1
ios iphone 源码 iphone桌面截图代码
iPhone4各版本shsh
iphone SDK 下载BT
卡iPhone在线支持MAX右键执行本站登录上iPhone,再选择你要卡的机型开始工作即可。 目前只有iphone 9、XS、XS Plus在线,建议卡XS在线比较真实,因为腾讯这边还没更新 腾讯这边如果更新XR、Max,软件也会进行更新 ...
这个版本是完整的,能够下载。 iphone开发的初级教程,如果你对开发iphone无从下手就看这本书吧。
Iphone开发系列源码——Image图片缩放随着手指Iphone开发系列源码——Image图片缩放随着手指Iphone开发系列源码——Image图片缩放随着手指Iphone开发系列源码——Image图片缩放随着手指Iphone开发系列源码——Image...
iPhone开发实战 iPhone开发 iPhone iPhone4 iPhone开发实战 iPhone开发 iPhone iPhone4
iphone4/iphone4s无信号解决方法
iphone 11和iphone 11 pro 维修资料
iphone wax源码.iphone wax源码.iphone wax源码.iphone wax源码.iphone wax源码.iphone wax源码.iphone wax源码.iphone wax源码.iphone wax源码.
jquery实现iphone滑动界面,jQuery iPhone UI 是 iPhone 平台上的 UI 界面包。