【代码笔记】iOS-柱状图
一,效果图。
二,工程图。
三,代码。
RootViewController.h

#import <UIKit/UIKit.h> @interface RootViewController : UIViewController
{
UIView* zhuView;
} @end

RootViewController.m

#import "RootViewController.h" @interface RootViewController () @end @implementation RootViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
} - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view. self.title=@"柱状图";
self.view.backgroundColor=[UIColor greenColor]; [self initZhuView:[NSArray arrayWithObjects:@"10",@"20",@"30",@"40",@"50",@"60",@"70",@"80",@"90",nil]]; }
#pragma -mark -柱状图初始化
- (void)initZhuView:(NSArray*)days
{ if ([[UIScreen mainScreen] bounds].size.height > 480) {
zhuView = [[UIView alloc] initWithFrame:CGRectMake(0, 310 - 45 + 50, 320, 150)];
}
else
{
zhuView = [[UIView alloc] initWithFrame:CGRectMake(0, 310 - 45, 320, 150)];
}
//柱状图所在的背景图
[self.view addSubview:zhuView]; //0天,50天,100天所在的竖线
UIView* shuView = [[UIView alloc] initWithFrame:CGRectMake(55, 0, 1, 120)];
[shuView setBackgroundColor:[UIColor orangeColor]];
[zhuView addSubview:shuView]; //0-9所在的横线
UIView* hengView = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMinX(shuView.frame), CGRectGetMaxY(shuView.frame), 320 - CGRectGetMinX(shuView.frame) - 20, 1)];
[hengView setBackgroundColor:[UIColor orangeColor]];
[zhuView addSubview:hengView]; NSArray* titles = [NSArray arrayWithObjects:@"100天",@"50天",@"0天", nil];
for (int i = 0 ; i < 3; i++) {
//天数所在Label
UILabel* yibaiLb = [[UILabel alloc] initWithFrame:CGRectMake(0, 5 + i* 50, 53, 15)];
[yibaiLb setText:[titles objectAtIndex:i]];
[yibaiLb setTextAlignment:NSTextAlignmentRight];
[yibaiLb setFont:[UIFont systemFontOfSize:14]];
[yibaiLb setBackgroundColor:[UIColor clearColor]];
[zhuView addSubview:yibaiLb];
} for (int i = 0; i < [days count]; i++) { int height = [[days objectAtIndex:i] intValue];
if(height>=100)
height=100; //红色的竖线的柱状图
UIImageView* imageView = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(shuView.frame) + 10 + i*25, CGRectGetMinY(hengView.frame) - height, 15, height)];
[imageView setBackgroundColor:[UIColor redColor]];
[zhuView addSubview:imageView]; //柱状图上的红色的数字Label
UILabel* dayLB = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMinX(imageView.frame) - 5, CGRectGetMinY(imageView.frame) - 10, 25, 10)];
[dayLB setTextAlignment:NSTextAlignmentCenter];
[dayLB setBackgroundColor:[UIColor clearColor]];
[dayLB setFont:[UIFont systemFontOfSize:10]];
[dayLB setText:[NSString stringWithFormat:@"%d",[[days objectAtIndex:i] intValue]]];
[zhuView addSubview:dayLB]; //1-9的数字所在的Label
UILabel* diLb = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMinX(imageView.frame), CGRectGetMaxY(hengView.frame) , 15, 20)];
[diLb setText:[NSString stringWithFormat:@"%d",i+1]];
[diLb setBackgroundColor:[UIColor clearColor]];
[diLb setTextAlignment:NSTextAlignmentCenter];
[diLb setFont:[UIFont systemFontOfSize:14]];
[zhuView addSubview:diLb];
}
}

【代码笔记】iOS-柱状图的更多相关文章
- IOS开发笔记 IOS如何访问通讯录
IOS开发笔记 IOS如何访问通讯录 其实我是反对这类的需求,你说你读我的隐私,我肯定不愿意的. 幸好ios6.0 以后给了个权限控制.当打开app的时候你可以选择拒绝. 实现方法: [plain] ...
- 【hadoop代码笔记】Mapreduce shuffle过程之Map输出过程
一.概要描述 shuffle是MapReduce的一个核心过程,因此没有在前面的MapReduce作业提交的过程中描述,而是单独拿出来比较详细的描述. 根据官方的流程图示如下: 本篇文章中只是想尝试从 ...
- 【hadoop代码笔记】hadoop作业提交之汇总
一.概述 在本篇博文中,试图通过代码了解hadoop job执行的整个流程.即用户提交的mapreduce的jar文件.输入提交到hadoop的集群,并在集群中运行.重点在代码的角度描述整个流程,有些 ...
- 【Hadoop代码笔记】目录
整理09年时候做的Hadoop的代码笔记. 开始. [Hadoop代码笔记]Hadoop作业提交之客户端作业提交 [Hadoop代码笔记]通过JobClient对Jobtracker的调用看详细了解H ...
- 笔记-iOS 视图控制器转场详解(上)
这是一篇长文,详细讲解了视图控制器转场的方方面面,配有详细的示意图和代码,为了使得文章在微信公众号中易于阅读,seedante 辛苦将大量长篇代码用截图的方式呈现,另外作者也在 Github 上附上了 ...
- <Python Text Processing with NLTK 2.0 Cookbook>代码笔记
如下是<Python Text Processing with NLTK 2.0 Cookbook>一书部分章节的代码笔记. Tokenizing text into sentences ...
- [学习笔记] SSD代码笔记 + EifficientNet backbone 练习
SSD代码笔记 + EifficientNet backbone 练习 ssd代码完全ok了,然后用最近性能和速度都非常牛的Eifficient Net做backbone设计了自己的TinySSD网络 ...
- DW网页代码笔记
DW网页代码笔记 1.样式. class 插入类样式 标签技术(html)解决页面的内容样式技术(css)解决页面的外观脚本技术 解决页面动态交互问题<form> ...
- 前端学习:JS(面向对象)代码笔记
前端学习:JS(面向对象)代码笔记 前端学习:JS面向对象知识学习(图解) 创建类和对象 创建对象方式1调用Object函数 <body> </body> <script ...
- 离屏渲染学习笔记 /iOS圆角性能问题
离屏渲染学习笔记 一.概念理解 OpenGL中,GPU屏幕渲染有以下两种方式: On-Screen Rendering 意为当前屏幕渲染,指的是GPU的渲染操作是在当前用于显示的屏幕缓冲区中进行. O ...
随机推荐
- About me
stay hungry, stay foolish VaJoy / 蓝邦珏 Addr:Tencent Shenzhen E-Mail:vajoy@qq.com 站内:http://space.cnbl ...
- 小小改动帮你减少bundle.js文件体积(翻译)
我已经从事过好多年的SPA开发工作,我发现很多的程序猿都从来不往 bundle.js 文件的体积上动脑筋,这让我有点懵逼. “安心洗路,等俺把代码混淆压缩后就一切666了”,若是有人这么说,我会翻白眼 ...
- 应用Grunt自动化地优化你的项目前端
在不久前我曾写了一篇 应用r.js来优化你的前端 的文章,为大家介绍了r.js这个实用工具,它可以很好地压缩.合并前端文件并打包整个项目.但是如果将r.js放到项目中,我们不得不顾及到一个问题——项目 ...
- Leetcode 笔记 110 - Balanced Binary Tree
题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For ...
- [转]Linux下g++编译与使用静态库(.a)和动态库(.os) (+修正与解释)
在windows环境下,我们通常在IDE如VS的工程中开发C++项目,对于生成和使用静态库(*.lib)与动态库(*.dll)可能都已经比较熟悉,但是,在linux环境下,则是另一套模式,对应的静态库 ...
- 计算机人物系列-Mauchly,Eckert,Goldstine
关键词:莫尔学院(Moore School),阿伯丁试验场(Aberdeen Proving Ground), 雷明顿兰德公司(Remington Rand Corporation), IBM院士(I ...
- NodeJs+http+fs+request+cheerio 采集,保存数据,并在网页上展示(构建web服务器)
目的: 数据采集 写入本地文件备份 构建web服务器 将文件读取到网页中进行展示 目录结构: package.json文件中的内容与上一篇一样:NodeJs+Request+Cheerio 采集数据 ...
- jQuery的DOM操作实例(1)——选项卡&&Tab切换
一.原生JavaScript编写tab切换 二.jQuery编写tab切换 在用jQuery编写选项卡过程中,重要的事搞清楚 .eq() 和 .index() 的使用方法. .eq()是jQuery遍 ...
- android官方下拉刷新控件SwipeRefreshLayout的使用
可能开发安卓的人大多数都用过很多下拉刷新的开源组件,但是今天用了官方v4支持包的SwipeRefreshLayout觉得效果也蛮不错的,特拿出来分享. 简介:SwipeRefreshLayout组件只 ...
- Events基本概念----Beginning Visual C#
span.kw { color: #007020; font-weight: bold; } code > span.dt { color: #902000; } code > span. ...